C语言编程题.docx

上传人:b****5 文档编号:8808845 上传时间:2023-05-15 格式:DOCX 页数:29 大小:20.69KB
下载 相关 举报
C语言编程题.docx_第1页
第1页 / 共29页
C语言编程题.docx_第2页
第2页 / 共29页
C语言编程题.docx_第3页
第3页 / 共29页
C语言编程题.docx_第4页
第4页 / 共29页
C语言编程题.docx_第5页
第5页 / 共29页
C语言编程题.docx_第6页
第6页 / 共29页
C语言编程题.docx_第7页
第7页 / 共29页
C语言编程题.docx_第8页
第8页 / 共29页
C语言编程题.docx_第9页
第9页 / 共29页
C语言编程题.docx_第10页
第10页 / 共29页
C语言编程题.docx_第11页
第11页 / 共29页
C语言编程题.docx_第12页
第12页 / 共29页
C语言编程题.docx_第13页
第13页 / 共29页
C语言编程题.docx_第14页
第14页 / 共29页
C语言编程题.docx_第15页
第15页 / 共29页
C语言编程题.docx_第16页
第16页 / 共29页
C语言编程题.docx_第17页
第17页 / 共29页
C语言编程题.docx_第18页
第18页 / 共29页
C语言编程题.docx_第19页
第19页 / 共29页
C语言编程题.docx_第20页
第20页 / 共29页
亲,该文档总共29页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

C语言编程题.docx

《C语言编程题.docx》由会员分享,可在线阅读,更多相关《C语言编程题.docx(29页珍藏版)》请在冰点文库上搜索。

C语言编程题.docx

C语言编程题

---

1.短信计费0.1元,但限定每条短信的内容70个字以内(包括用手机发短信,一般一条短信资费为在70个字)。

如果你所发送的一条短信超70个字,则大多数手机会按照70个字一条过了每短信的限制把它分割成多条短信发假设已经知道你当月所发送的每条短信的字试统送。

数,计一下你当月短信的总资费。

#include

#include

#include

#include

#include

#include

#include

#definelllonglong

#defineinf2147483647

usingnamespacestd;

intn;

intmain()

{

cin>>n;

doubleans=0;

-----

---

for(inti=1;i<=n;i++)

-----

---

{

intx;

cin>>x;

ans=ans+((x-1)/70+1)*0.1;

}

printf(%.1lf\n,ans);

return0;

}

2.集体照医学部口腔3班n位同学约定拍集体照,n大于1且不超过100。

摄影师要求同学按照身高站成两排,保证第二排的人身高都要大于等于第一排的人,且第二排的人数和第一排的人数相等或者比第一排多一个人。

输入n位同学的身高,请问第二排中身高最矮的人的身高是多少?

#include

#include

#include

#include

#include

-----

---

#include

-----

---

#include

#definelllonglong

#defineinf2147483647

usingnamespacestd;

intn;

inta[105];

intmain()

{

while(scanf(%d,&n))

{

if(n==0)return0;

for(inti=1;i<=n;i++)

cin>>a[i];

sort(a+1,a+n+1);

cout<

}

return0;

}

3.1020跳格问题

-----

---

有一种游戏,在纸上画有很多小方格,第一个方格为起点(S),最后一个方格为终点。

有一

-----

---

个棋子,初始位置在起点上,棋子每次可移动一次,棋子在起点时,可向前移动一个格子到

Ni进行移动。

如果Ni大于第二个方格内;棋子在其他方格内时,可根据方格内的数零,字就向前移动Ni个格子;如果Ni小于零,就向后移动-Ni个格子;如果Ni等于零,则此次原

地不动一次,在下一步移动时可向前移动一步到下一个格子。

显然,如果仅按此方案,会出

为防止这种情况发现棋子永远移动不到终点的情我们规定,形。

生,当棋子再次来到它曾经

到过的方格时,它需要原地不动一次,在下一步移动时可向前移动一步到下一个格子。

按此

方案,棋子总能够走到终点(F)。

如果给定一个方格图,试求棋子要走多少步才能从起点走

到终点。

(注:

当然还可能会出现向前移Ni个格子就跑过终点了,则把棋子放到终点上。

动)(如图所示,其中如果Ni太小,使得棋子向后移动跑过了起点,则把棋子放到起点上。

S

代表起点,F代表终点)(只有离开后再次来到一个方格时,才算来到它曾经到过的方格,

)包括起点S

#include

#include

#include

#include

#include

#include

#include

#definelllonglong

#defineinf2147483647

-----

---

usingnamespacestd;

-----

---

intn,ans;

inta[105];

boolvis[105];

voiddfs(intx)

{

if(x<1)

x=1;

if(x>n+2)

x=n+2;

if(vis[x])

{

if(a[x])ans+=2;

elseans+=1;

dfs(x+1);

}

else

{

vis[x]=1;

if(x==n+2)return;

ans++;

-----

---

dfs(x+a[x]);

}

-----

---

}

intmain()

{

scanf(%d,&n);

a[1]=1;

for(inti=2;i<=n+1;i++)

cin>>a[i];

dfs

(1);

cout<

return0;

}4.配对碱基链脱氧核糖核酸(DNA)由两条互补的碱基链以双螺旋的方式结合而成。

而构成DNA的碱基共有4种,分别为腺瞟呤(A)、鸟嘌呤(G)、胸腺嘧啶(T)和胞嘧啶(C)。

我们知道,在两条互补碱基链的对应位置上,腺瞟呤总是和胸腺嘧啶配对,鸟嘌呤总是和胞嘧啶配对。

你的任务就是根据一条单链上的碱基序列,给出对应的互补链上的碱基序列。

#include

#include

-----

---

#include

-----

---

#include

#include

#include

#include

#definelllonglong

#defineinf2147483647

usingnamespacestd;

intn;

stringx;

intmain()

{

scanf(%d,&n);

for(inti=1;i<=n;i++)

{

cin>>x;

for(intj=0;j

{

if(x[j]=='T')

x[j]='A';

elseif(x[j]=='A')

-----

---

x[j]='T';

elseif(x[j]=='C')

-----

---

x[j]='G';

else

x[j]='C';

}

cout<

}

return0;

}

5.打鱼还是晒网111990中国有句俗语叫“三天打鱼两天晒网”。

某人从年月日起开始“三天打鱼两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”。

注意要区分闰年和不是闰年的两种情况

#include

#include

#include

#include

#include

#include

-----

---

#include

-----

---

#definelllonglong

#defineinf2147483647

usingnamespacestd;

inty,m,d;

intmm[12]={31,28,31,30,31,30,31,31,30,31,30,31};

inttot;

intmain()

{

cin>>y>>m>>d;

for(inti=1990;i

if((i%4==0&&i%100!

=0)||i%400==0)

tot+=366;

elsetot+=365;

for(inti=1;i

if(((y%4==0&&y%100!

=0)||y%400==0)&&i==2)

tot+=29;

else

tot+=mm[i-1];

tot+=(d-1);

if(tot%5<=2)

-----

---

puts(

ishing);

else

-----

---

puts(sleeping);

return0;

}

优先队列6.给定一个初始数字集合,对其做如下两种操作:

添加一个新的数字1.将集合中当前最小的数字取出2.只取出其中一个。

(输出并删除),如果最小的数字有多个,

#include

#include

#include

#include

#include

#include

#include

#include

#definelllonglong

#defineinf2147483647

usingnamespacestd;

-----

---

intn,m;

-----

---

structdata{

inta[200005];

intcnt;

boolempty(){

returncnt==0;

}

voidpush(intx){

a[++cnt]=x;

intp=cnt;

while(p>1&&a[p]

{

swap(a[p],a[p/2]);

p=p/2;

}

}

inttop(){

returna[1];

}

voiddown(intx){

intt=x<<1;

-----

---

if(t>cnt)return;

if(t+1<=cnt&&a[t+1]

-----

---

t++;

if(a[t]

{

swap(a[t],a[x]);

down(t);

}

}

voidpop(){

a[1]=a[cnt];

cnt--;

down

(1);

}

}q;

intmain()

{

cin>>n;

for(inti=1;i<=n;i++)

{

intx;

cin>>x;

-----

---

q.push(x);

}

-----

---

cin>>m;

charopt[15];

for(inti=1;i<=m;i++)

{

scanf(%s,opt);

if(opt[0]=='E')

{

if(q.empty())

puts(NULL);

else

{

cout<

q.pop();

}

}

else

{

intx;

cin>>x;

q.push(x);

-----

---

}

}

-----

---

return0;

}

7.护林员盖房子在一片保护林中,护林员想要盖一座房子来居住,但他不能砍伐任何树木。

现在请你帮他计算:

保护林中所能用来盖房子的矩形空地的最大面积。

#include

#include

#include

#include

#include

#include

#include

#include

#definelllonglong

#defineinf2147483647

usingnamespacestd;

intn,m;

intans;

-----

---

intv[25][25];

-----

---

boolcheck(inta,intb,intc,intd)

{

for(inti=a;i<=c;i++)

for(intj=b;j<=d;j++)

if(v[i][j])return0;

return1;

}

intmain()

{

cin>>n>>m;

for(inti=1;i<=n;i++)

for(intj=1;j<=m;j++)

cin>>v[i][j];

for(inti=1;i<=n;i++)

for(intj=1;j<=m;j++)

for(intk=i;k<=n;k++)

for(intl=j;l<=m;l++)

if(check(i,j,k,l))

ans=max(ans,(k-i+1)*(l-j+1));

cout<

-----

---

return0;

}

-----

---

8.汽车限行为了缓解交通压力、减少空气污染,B市市政府决定在工作日(周一至周五)对机动车进行2000年1

限行,每辆机动车每周将有一个工作日不能出行,但周末不限行。

假设该政策从

日起开始执行。

限行安排为:

1月

尾号为1和6:

周一限行

周二限2和7尾号为:

周三和8行尾号为3

周9限行尾号为4和四限行和字母:

周五限行5尾号为、0日为周六,现在给出一些日期和车牌号,求问该机动车在该天是否限行。

11已知2000年月

#include

#include

#include

#include

#include

#include

#include

#definelllonglong

-----

---

#defineinf2147483647

-----

---

usingnamespacestd;

intT;

inty,m,d;

intmm[12]={31,28,31,30,31,30,31,31,30,31,30,31};

intmain()

{

cin>>T;

while(T--)

{

charch;

cin>>y>>ch>>m>>ch>>d;

strings;

cin>>s;

intday,tot=0;

if(s[5]>'9'||s[5]<'0')day=5;

elseday=(s[5]-'0')%5;

if(day==0)day=5;

for(inti=2000;i

if((i%4==0&&i%100!

=0)||i%400==0)

tot+=366;

-----

---

elsetot+=365;

for(inti=1;i

-----

---

if(((y%4==0&&y%100!

=0)||y%400==0)&&i==2)

tot+=29;

else

tot+=mm[i-1];

tot+=(d-1);

if((tot+6-1)%7+1==day)

puts(yes);

else

puts(

o);

}

return0;

}

9.人工智能全世界的计算机学家们至今仍在不断努人工智能一直是计算机学所追求的一个很高的境界,力力求达到这个境界。

这道题也跟“人工智能”有关。

*I=U(功率)P学过初中物理的同学都应该知道物理学中的这个公式(电压)(电流)。

如果给定其中的任意两个值,第三个值都是很容易求的,这个就是本题的任务。

-----

---

#include

-----

---

#include

#include

#include

#include

#include

#include

#include

#definelllonglong

#defineinf2147483647

usingnamespacestd;

intT;

strings;

mapmp;

doubleget(intx)

{

doublev=0,t=1;

for(inti=x;i

if(s[i]>='0'&&s[i]<='9')

{

if(t==1)

-----

---

v=v*10+s[i]-'0';

else

-----

---

{

v=v+(s[i]-'0')*t;

t*=0.1;

}

}

elseif(s[i]=='.')

t=0.1;

elseif(s[i]=='m')

v*=0.001;

elseif(s[i]=='k')

v*=1000;

elseif(s[i]=='M')

v*=1000000;

elsebreak;

returnv;

}

intmain()

{

cin>>T;

charch;

-----

---

ch=getchar();

for(intt=1;t<=T;t++)

-----

---

{

printf(Problem#%d\n,t);

getline(cin,s);

mp['I']=mp['U']=mp['P']=-1;

for(inti=0;i

if(s[i]=='=')

mp[s[i-1]]=get(i+1);

if(mp['I']==-1)

printf(I=%.2lfA\n,mp['P']/mp['U']);

if(mp['U']==-1)

printf(U=%.2lfV\n,mp['P']/mp['I']);

if(mp['P']==-1)

printf(P=%.2lfW\n,mp['U']*mp['I']);

}

return0;

}

专业资料学习资料教育培训考试建筑装潢资料

-----

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2