资源描述:
《部分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、求高于平均分的学生学号及成绩(学号和成绩人工输入)d
2、oublefind(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;}}intmain(intargc,char*argv[]){find(0,0);}3
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(str))?Yes:No);}4、组合问题(从M个不同字符中任取N个字符的所有组合)voidfind(cha
4、r*source,char*result,intn){if(n==1){ain(intargc,char*argv[]){intconstn=3;char*source=ABCDE,result[n+1]={0};if(n>0strlen(source)>0n<=strlen(source))find(source,result,3);}5、分解成质因数(如435234=251*17*17*3*2,据说是华为笔试题)voidprim(intm,intn){if(m>n){%n!=0)n++;m/=n;prim(m,n);printf(
5、%d*,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','o','X','X','
6、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
7、
8、Y==MAX_SIZE){for(inti=0;i<MAX_SIZE;i++)for(intj=0;j&
9、lt;MAX_SIZE;j++)printf(%c%c,Maze[j],j<MAX_SIZE-1?'':'');}elsefor(intk=0;k<4;k++)if(X>=0Y>=0Y<MAX_SIZEX<MAX_SIZE'o'==Maze[X][Y]){Maze[X][Y]='';FindPath(X+V[k],Y+H[k]);Maze[X][Y]='o';}}intmain(intargc,char*argv[]){FindPath(1,0);}7、随机分配座位,共50个学生,使学号相邻的同学座位不能相邻(早些时候
10、用C#写的,没有用C改写)。staticvoidMa