资源描述:
《部分IT公司笔试算》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、部分IT公司笔试算法题算法,笔试部分IT公司笔试算法题1、将一整数逆序后放入一数组中(要求递归实现)voidconvert(int*result,intn){if(n>=10)convert(result+1,n/10);*result=n%10;}intmain(intargc,char*argv[]){intn=123456789,result[20]={};convert(result,n);printf("%d:",n);for(inti=0;i<9;i++)printf("%d",result);}2、求高于平均分的学生
2、学号及成绩(学号和成绩人工输入)doublefind(inttotal,intn){intnumber,score,average;scanf("%d",&number);if(number!=0){scanf("%d",&score);average=find(total+score,n+1);if(score>=average)printf("%d:%d",number,score);returnaverage;}else{printf("Average=%d",total/n);returntotal/n;}}int
3、main(intargc,char*argv[]){find(0,0);}3、递归实现回文判断(如:abcdedbca就是回文,判断一个面试者对递归理解的简单程序)intfind(char*str,intn){if(n<=1)return1;elseif(str[0]==str[n-1])returnfind(str+1,n-2);elsereturn0;}intmain(intargc,char*argv[]){char*str="abcdedcba";printf("%s:%s",str,find(str,strlen(s
4、tr))?"Yes":"No");}4、组合问题(从M个不同字符中任取N个字符的所有组合)voidfind(char*source,char*result,intn){if(n==1){while(*source)printf("%s%c",result,*source++);}else{inti,j;for(i=0;source!=0;i++);for(j=0;result[j]!=0;j++);for(;i>=n;i--){result[j]=*source++;result[j+1]=' ';find(source,r
5、esult,n-1);}}}intmain(intargc,char*argv[]){intconstn=3;char*source="ABCDE",result[n+1]={0};if(n>0&&strlen(source)>0&&n<=strlen(source))find(source,result,3);}5、分解成质因数(如435234=251*17*17*3*2,据说是华为笔试题)voidprim(intm,intn){if(m>n){while(m%n!=0)n++;m/=n;prim(m,n);printf("%d
6、*",n);}}intmain(intargc,char*argv[]){intn=435234;printf("%d=",n);prim(n,2);}6、寻找迷宫的一条出路,o:通路;X:障碍。(大家经常谈到的一个小算法题)#defineMAX_SIZE8intH[4]={0,1,0,-1};intV[4]={-1,0,1,0};charMaze[MAX_SIZE][MAX_SIZE]={{'X','X','X','X','X','X','X','X'},{'o','o','o','o','o','X','X','X'},{'X
7、','o','X','X','o','o','o','X'},{'X','o','X','X','o','X','X','o'},{'X','o','X','X','X','X','X','X'},{'X','o','X','X','o','o','o','X'},{'X','o','o','o','o','X','o','o'},{'X','X','X','X','X','X','X','X'}};voidFindPath(intX,intY){if(X==MAX_SIZE
8、
9、Y==MAX_SIZE){for(inti=0;i<
10、MAX_SIZE;i++)for(intj=0;j=0&&Y>=0&&Y<