1、9) ai=xi-; else if(xiAZ+10;az unsigned aIndex1=0,aIndex2=0,bIndex=0; int iyu=0; while(aIndex1xLen) iyu=0; aIndex2=aIndex1; while(aIndex2=0&iyu=9) bbIndex=iyu+ else bbIndex=iyu-10+ bIndex+; bbIndex=0 strrev(b); printf(%sn,b); return 0;输入一个数组的值,求出各个值从小到大排序后的次序。输入:输入的第一个数为数组的长度,后面的数为数组中的值,以空格分割输出:各输入的值
2、按从小到大排列的次序。sampleinput:4-3 75 12 -3output:1 3 2 1int exist(int arr,int len,int elem) for(int i=0;len; if(arri=elem) return i; arrlen=elem; return -1; int inputNum,i,j,plen,temp; int nums1000,num11000; while(scanf(%dinputNum)!=EOF) for(i=0,plen=0;inputNum; scanf(numsi); if(exist(num1,plen,numsi)=-1)
3、plen+; for(i=1;plen; for(j=0;jnum1j+1) temp=num1j; num1j=num1j+1; num1j+1=temp; for(i=0; if(i!=0) printf( ); printf(,exist(num1,plen,numsi)+1); printf(n/*给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号,隔开。现在请计算A+B的结果,并以正常形式输出。*/iostreamstringusing namespace std;int covert(string input) int l=input.length(); long lon
4、g sum=0; char temp= for (int i=0;l; temp=inputi; if(temptempinputAinputB) A=covert(inputA); B=covert(inputB); coutA+Blength-1-lastJidx)return false; if(front=rear&middle=o return true; else string newStr=input.erase(length-front.length(); newStr=newStr.erase(firstZIdx+1,1); return judge(newStr);inpu
5、tA) if(judge(inputA) coutAcceptedn else cout/统计文件中的单词数目int _tmain(int argc, _TCHAR* argv) /read ifstream ifs(zxh.txt,ios:in); char c;int wordNum=0;bool isSpace=true; while(!ifs.eof() c=ifs.get(); if(c= |c=nrt if(!isSpace)/上一个不是空白字符 这一个是 isSpace=true; wordNum+; if(isSpace)/上一个是空白字符 这一个不是 isSpace=fals
6、e; if(c!c!=-1) wordNum+; ifs.close(); couta;1输入一个数列以0位结束标志,建立链式线性表,查找其中最大的数并输出删除释放节点,然后对剩余的进行排序,并输出释放节点struct node int data; node* next;void printList(node*head)/print node * p=head-next; while(p!=NULL)p-dataendl; node* head=new node(); head-next=NULL; node* n,*p=head; int length=0;c)/create) break;
7、 if(c coutdata=c-48; p-next=n; length+; printList(head); /find max int max=0; n=p=head;/parent while(p-next! if(p-next-datamax) max=p-data; n=p;/n point to the maxs parentThe max num is :max n-next=n- free(p); length-; /sort p=head; for(int i=length;i0;i-) p=head; for(int j=0;i-1; if(p-data) n=p- p-
8、 n- p=p- /print and free while(head-head- p=head- free(head); head=p; free(head); int m; cinm;/输入一个数列以0位结束标志,建立二叉遍历数,并对其进行逆中序遍历,释放空间/需要注意的是 释放空间时候 只用在每次递归释放root就ok 不要重复释放root-lchild 和 root-rchildstruct treeNode char data; treeNode* lchild,*rchild;treeNode* createTree()c; if(c=) return NULL; treeNode
9、 * root=new treeNode(); root-data=c;lchild=createTree();rchild=createTree(); return root;void opposingMidTraverse(treeNode*root) if(root=NULL) return; if(root-rchild!=NULL) opposingMidTraverse(root-rchild);root-lchild!lchild); free(root); treeNode*root=createTree(); opposingMidTraverse(root);/*第三题是
10、输入一个ip地址串,判断是否合法合法ip地址满足: 无非法字符(非数字字符和.).之间的数字在0-255之间 不是C、D类ip,ips0 string ip;bigWhile:ip) int ips4; for(int i=0;ip.length(); if(!isdigit(ipi)&ipi!) coutip地址只能是数字或者.组成,您输入了非法字符吧n goto bigWhile; char* c_ip=(char*)ip.c_str(),*strptr; strptr=strtok(c_ip,. char*ips_str=(char*)malloc(sizeof(char*)*10);i
11、nt i=0; while(strptr! ips_stri=strptr; i+; strptr=strtok(NULL, if(i!=4)请输入合法的ipv4地址,四段哦! goto bigWhile;4; ipsj=atoi(ips_strj); if(ipsj255)ip地址字段只能是0-255的数字! if(ips0=127|ips0=224) ip地址只能是ABC类地址,而且也不能是本地回环地址啊! if(ips0ips0127&=191)/B类 if(ips2=0&ips3=0)|(ips2=255& if(ips0=172&ips1=16&ips1=31)合法ip地址不能是B类
12、专用地址(172.16.0.0-171.31.255.255)n191&=223)/C类 if(ips3=0)|(ips3=255) if(ips0=192&ips1=168)合法ip地址不能是C类专用地址(192.168.0.0-192.168.255.255)nips2ips3是合法ip地址O(_)On第一题:对给定的一个字符串,找出有重复的字符,并给出其位置,如:abcaaAB12ab12输出:a,1;a,4;a,5;a,10 b,2;b,11 1,8;1,12 2,9;2,13 string inputStr; char current; int index=-1,lastIndex,firstIndex;inputStr)inputStr.length(); current=inputStri; firstIndex=inputStr.find_first_of(current); lastIndex=inputStr.find_last_of(current); if(firstIndex!=lastIndex)&
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2