【精选】华为C语言面试题.pdfVIP

  • 4
  • 0
  • 约9.77千字
  • 约 16页
  • 2017-12-06 发布于贵州
  • 举报
【精选】华为C语言面试题

1.编写一个 C 函数,该函数在一个字符串中找到可能的最长的子字符串,且该字符串是 由同一字符组成的。 char* search(char* cpSource, char ch) { if(cpSource==NULL) return 0; 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; } 2.请编写一个 C 函数,该函数在给定的内存区域搜索给定的字符,并返回该字符所在位 置索引值。 int search(char*cpSource, char ch) { if(cpSource==NULL) return 0; int i; int n=strlen(cpSource); for(i=0; in; i++) if(ch == cpSource[i]) return i; } 3.写一个函数比较两个字符串str1 和str2 的大小,若相等返回0,若str1 大于str2 返回1,若str1 小于str2返回-1 int strcmp ( const char *dst,const char * src) { int ret = 0 ; while ( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) *dst++*src++); if ( ret 0 ) ret = -1 ; else if ( ret 0 ) ret = 1 ; return( ret ); } 4.求1000!的未尾有几个0 每个0拆成2*5 的形式,因为2*5 会参生一个0,例:90=2*5*9.因总的2 因子很多,所 以0 的个数,由5 因子个数决定,即等于5 因子个数.求出1-1000 里,能被5 整除的数 的个数n1,能被25 整除的数的个数n2,能被125整除的数的个数n3,能被625整除的数 的个数n4.1000!末尾的零的个数=n1+n2+n3+n4; int find5(int num) { int ret=0; while (num%5==0) { num/=5; ret++; } return ret; } int main() { 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; } 5. 有双向循环链表结点定义为: struct node { int data; struct node *front,*next; }; 有两个双向循环链表 A,B,知道其头指针为:pHeadA,pHeadB,请写一函数将两链表中 data 值相同的结点删除 BOOL DeteleNode(Node *pHeader, DataType Value) { if (pHeader == NULL) return; BOOL

文档评论(0)

1亿VIP精品文档

相关文档