enjoy-linux的ChinaUnix博客boydengsm.blog.chinaunix.net
enjoy-linux
全部博文(10)
2012年(10)
cherish5
wenlan88
mxgsgtc
午后便会
zhuimeng
qujia_19
wisedd
LovxeLX
liuyingj
linux大
crazyks
分类:
2012-11-02 21:14:28
原文地址:C语言面试算法题(二) 作者:frankzfz
#include <stdio.h> #include <stdlib.h> #include <string.h> int FindMax_NumStr(char *outputstr,char *inputstr) { char *in = inputstr,*out = outputstr,*temp; char *final; int count = 0; int maxlen = 0; int i; while(*in!='\0') { if(*in > 47 && *in < 58) { for(temp = in;*in> 47 && *in <58;in++) count++; } else in++; if(maxlen < count) { maxlen = count; count = 0; final = temp; } } for(i =0;i<maxlen;i++) { *out = *final; out++; final++; } *out = '\0'; return maxlen; } void main(void) { char input[]="abc123def123456eec123456789dd"; char output[50] = {0}; int maxlen; maxlen = FindMax_NumStr(output,input); printf("the str %s\n",output); printf("the maxlen is %d\n",maxlen); }
#include <stdio.h> #define NUM 1000 int find5(int num) { int ret = 0; while(num%5==0) { num/=5; ret++; } return ret; } int main(void) { int result = 0; int i; for(i=5;i<=NUM;i+=5) result +=find5(i); printf("the total zero number is %d\n",result); return 0; }
char * search(char *cpSource, char ch) { char *cpTemp=NULL, *cpDest=NULL; int iTemp, iCount=0; while(*cpSource) { if(*cpSource == ch) { iTemp = 0; cpTemp = cpSource; while(*cpSource == ch) ++iTemp, ++cpSource; if(iTemp > iCount) iCount = iTemp, cpDest = cpTemp; if(!*cpSource) break; } ++cpSource; } return cpDest; }
上一篇:ARM的流水线与PC值的关系
下一篇:2012-12-27
登录 注册