围城
List_linux
全部博文(135)
IPC(1)
bootloader(4)
iptables&netfilt(0)
Bluetooth(1)
wireless(1)
wireless(0)
udev(3)
luci(5)
PCI(3)
2019年(3)
2018年(7)
2017年(14)
2016年(15)
2015年(34)
2014年(9)
2013年(53)
lzsos369
yanglian
julius10
Pantj
雪猪tt
ycx10000
huang_gu
yuanzh78
j1nyu
xuxiangq
供奉帅哥
分类: C/C++
2013-08-12 17:21:35
原文地址: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; }
上一篇:中兴笔试题
下一篇:C语言面试算法题(一)
登录 注册