资源描述:
《IT公司算法笔试试题》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、部分IT公司笔试算法题个人总结,算法未必最合理,仅供参考:shayg@163.com1、将一整数逆序后放入一数组中(要求递归实现)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",r
2、esult[i]);}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",to
3、tal/n);returntotal/n;}}intmain(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("
4、%s:%s",str,find(str,strlen(str))?"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[i]!=0;i++);for(j=0;result[j]!=0;j++);for(;i>=n;i--){result[j]=*so
5、urce++;result[j+1]=' ';find(source,result,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){w
6、hile(m%n!=0)n++;m/=n;prim(m,n);printf("%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','
7、X','X'},{'o','o','o','o','o','X','X','X'},{'X','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
8、,intY){if(X==MAX_SIZE
9、
10、Y==MAX_SIZE){for(inti=0;i