




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
2023年C语言面试算法题(附答案)
如: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
#include
intpop(int*);
intpush(int);
voidcombination(int,int);
intstack[3]={0};
inttop=-1;
intmain()
{
intn,m;
n=5;
m=3;
combination(n,m);
printf(\n);
}
voidcombination(intm,intn)
{
inttemp=m;
push(temp);
while(1)
{
if(1==temp)
{
if(pop(temp)stack[0]==n)
break;
}
elseif(push(--temp))
{
printf(%d%d%d\n,stack[0],stack[1],stack[2]);
pop(temp);
}
}
}
intpush(inti)
{
stack[++top]=i;
if(top2)
return0;
else
return1;
}
intpop(int*i)
{
*i=stack[top--];
if(top=0)
return0;
else
return1;
}
2.、用指针的”方法,将字符串“ABCD1234efgh”前后对调显示
#include
#include
intmain()
{
charstr[]=ABCD123efgh;
intlength=strlen(str);
char*p1=str;
char*p2=str+length-1;
while(p1
{
charc=*p1;
*p1=*p2;
*p2=c;
++p1;
--p2;
}
printf(strnowis%s\n,str);
return1;
}
3.给定字符串A和B,输出A和B中的最大公共子串。比方A=aocdfeB=pmcdfa则输出cdf
#include
#include
#include
char*commanstring(charshortstring[],charlongstring[])
{
inti,j;
char*substring=malloc(256);
if(strstr(longstring,shortstring)!=NULL)
returnshortstring;
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)
returnsubstring;
}
}
returnNULL;
}
voidmain(void)
{
char*str1=aocdfe;
char*str2=pmcdfa;
char*comman=NULL;
if(strlen(str1)strlen(str2))
comman=commanstring(str2,str1);
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 美甲合同转让协议书模板
- 花草租赁解除合同协议书
- 船员培训专项协议书模板
- 网页设计团队外包协议书
- 风力发电安装转让协议书
- 签了购房协议不给签合同
- 电梯加楼梯施工合同协议
- 职工餐厅承包合同协议书
- 门店分红股东协议书范本
- 腺肌病的护理
- 北京市朝阳区2024-2025学年高一下学期期末语文试题(含答案)
- 安徽高危人员管理办法
- 牙外伤护理配合课件
- 2025年辅警招聘考试试题及参考答案
- 2025年湖南省高考物理真题
- 2025年吉林省中考数学试卷真题(含答案详解)
- 党课课件含讲稿:以作风建设新成效激发干事创业新作为
- 军事知识科普儿童课件
- 谷歌付费协议书
- 爆破三员安全培训课件
- 《安全生产考核巡查办法》知识培训
评论
0/150
提交评论