网站大量收购独家精品文档,联系QQ:2885784924

C语言面试算法题.doc

  1. 1、本文档共6页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
C语言面试算法题

 HYPERLINK /thread-2275308-1-1.html C语言面试算法题 1.求组合数: 求n个数(1....n)中k个数的组合.... 如:combination(5,3) 要求输出:543,542,541,532,531,521,432,431,421,321, /* 求组合数: 求n个数(1....n)中k个数的组合.... ? ?? ?? ???如:combination(5,3) ??要求输出:543,542,541,532,531,521,432,431,421,321, */ #include stdio.h #include error.h int pop(int *); int push(int ); void combination(int ,int); int stack[3]={0}; int top = -1; int main() { ??int n,m; ? ? n = 5; ? ? m = 3; ??combination(n,m); ??printf(\n); } void combination(int n(5),int m(3)) { ??int temp = m; int push(int i){ ??push(temp); stack[++top]=i; ??while(1) ?if(top2) ??{ return 0; ? ? if(1==temp) else ? ? { return 1; ? ?? ?if(pop(temp) stack[0]==n) ? ?? ???break; ? ? } ? ? else if(push(--temp)) ? ? { ? ?? ?printf(%d%d%d\n,stack[0],stack[1],stack[2]); ? ?? ?pop(temp); ? ? } ??} } int push(int i) { ??stack[++top]=i; ??if(top2) ? ? return 0; ??else ? ? return 1; } int pop(int *i) { ??*i = stack[top--]; ??if(top=0) ? ? return 0; ??else ? ? return 1; } 复制代码 2.、用指针的方法,将字符串“ABCD1234efgh”前后对调显示 #include stdio.h #include string.h int main() { ??char str[]=ABCD123efgh; ??int length = strlen(str); ??char *p1= str; ??char *p2 = str+length -1; ??while(p1p2) ??{ ? ? char c = *p1; ? ? *p1 = *p2; ? ? *p2 = c; ? ? ++p1; ? ? --p2; ??} ??printf(str now is %s\n,str); ??return 1; } 复制代码 3.给定字符串A和B,输出A和B中的最大公共子串。比如A=aocdfe B=pmcdfa 则输出cdf #include stdio.h #include stdlib.h #include string.h char *commanstring(char shortstring[],char longstring[]) { ??int i,j; ??char *substring = malloc(256); ??if(strstr(longstring,shortstring)!=NULL) ? ? return shortstring; ??for(i=strlen(shortstring)-1;i0;i--) ??{ ? ? for(j=0;j=strlen(shortstring)-i;j++) ? ? { ? ?? ?memcpy(substring,shortstring[j],i); ? ? substring[i]=\0; ? ? if(strstr(longstring,substring)!=NULL) ? ?? ?return substring; ? ? } ??} ??return NULL; } void main(void) { ??char *str1 = aocdfe; ??char *str2 = pmcdfa; ??char *com

文档评论(0)

xy88118 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档