中国石油大学华东c语言在线测评答案 第10章字符串级亲测正确资料.docx

上传人:b****1 文档编号:483802 上传时间:2022-10-10 格式:DOCX 页数:23 大小:79.67KB
下载 相关 举报
中国石油大学华东c语言在线测评答案 第10章字符串级亲测正确资料.docx_第1页
第1页 / 共23页
中国石油大学华东c语言在线测评答案 第10章字符串级亲测正确资料.docx_第2页
第2页 / 共23页
中国石油大学华东c语言在线测评答案 第10章字符串级亲测正确资料.docx_第3页
第3页 / 共23页
中国石油大学华东c语言在线测评答案 第10章字符串级亲测正确资料.docx_第4页
第4页 / 共23页
中国石油大学华东c语言在线测评答案 第10章字符串级亲测正确资料.docx_第5页
第5页 / 共23页
点击查看更多>>
下载资源
资源描述

中国石油大学华东c语言在线测评答案 第10章字符串级亲测正确资料.docx

《中国石油大学华东c语言在线测评答案 第10章字符串级亲测正确资料.docx》由会员分享,可在线阅读,更多相关《中国石油大学华东c语言在线测评答案 第10章字符串级亲测正确资料.docx(23页珍藏版)》请在冰豆网上搜索。

中国石油大学华东c语言在线测评答案 第10章字符串级亲测正确资料.docx

中国石油大学华东c语言在线测评答案第10章字符串级亲测正确资料

此文档收集于网络,如有侵权请联系网站删除10.1字符转换提取一个字符串中的所有数字字符(‘0'...‘9')将其转换为一个整数输出。

描述

个字符)。

输入一个以回车符为结束标志的字符串(少于80把字符串中的所有数字字符(‘0'...‘9')转换为一个整数并输出。

输出

#include

#include

intmain()

{

chars[80];

inti,k,n=0;

gets(s);

k=strlen(s);

for(i=0;i

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

n=n*10+(s[i]-'0');

printf(%d\n,n);

return0;

}

10.2合并字符串输入两个已经按从小到大顺序排列好的字符串,编写一个合并两个字符串的函数,使合并后的字符串,仍然是从小到大排列。

两个已经排好顺序(升序)的字符串输入:

输出:

一个合并在一起的有序(升序)的字符串要求:

设计一个效率尽量高的算法,对每个字符串只扫描一遍就可以了。

如果采用先进行串连接,然后再进行排序的算法,则效率太低了。

此文档仅供学习和交流.

此文档收集于网络,如有侵权请联系网站删除

#include

#include

intmain()

{

chara[100],b[100],t;

intk,i,j;

gets(a);gets(b);

strcat(a,b);

k=strlen(a);

*/

冒泡法排序/**/从1开始不能用字符串数组最后一项for(i=1;i

if(a[j]>a[j+1])

{t=a[j];

a[j]=a[j+1];

a[j+1]=t;}

puts(a);

return0;

}

10.3删除重复字符的字符串,删除串中的重复字符。

输入一个长度不超过100背景:

abacaeedabcdcd。

输入要检查的字符串,长度不超过输入:

100个字符。

例如:

abced。

删除重复字符后的字符串。

例如:

输出:

此文档仅供学习和交流.

此文档收集于网络,如有侵权请联系网站删除#include

#include

intmain()

{

chara[100],b[100];

intk,i,j;

gets(a);

k=strlen(a);

for(i=0;i

for(j=i+1;j

if(a[j]==a[i])a[j]='\0';

for(i=0;i

if(a[i]!

='\0')

printf(%c,a[i]);

printf(\

);

return0;

}

10.4删除字符串中指定字符s2s1中删除任何中有的字符。

s2输入两个字符串s1和,在s1

删除后的字符串s2两个字符串s1和输出:

输入:

#include

#include

此文档仅供学习和交流.

此文档收集于网络,如有侵权请联系网站删除intmain()

{

chars1[20],s2[20];

intk1,k2,i,j;

gets(s1);gets(s2);

k1=strlen(s1);k2=strlen(s2);

for(j=0;j

for(i=0;i

if(s1[i]==s2[j])s1[i]='\0';

j=0;

for(i=0;i

if(s1[i]!

='\0')

{s1[j]=s1[i];j++;}

s1[j]='\0';

puts(s1);

return0;

}

单词有多少10.5

时才停stop用空格或换行分开的字符串称为单词。

输入多行字符串,直到遇到了单词止。

最后输出单词的数量。

用于分割单词的空格或换行可能多于1个。

单词的数量输入:

多个字符串输出:

#include

#include

此文档仅供学习和交流.

此文档收集于网络,如有侵权请联系网站删除intmain()

{

chars[20];

inti,n=0;

for(i=0;;i++)

s[20]*/遇空格或换行则存入下一个{scanf(%s,s);/*scanf

strcmp*/gets(s),它对换行空格没反应,都存入同一s[],无法n++;/*不能if(strcmp(s,stop)==0)break;

}

printf(%d\n,n-1);

return0;

}

在指定位置插入字符串10.6

第一次出现的中的指定字符kk和s1中任意字符,在s1s2输入两个字符串s1、s2并输出。

位置处插入字符串k和s2s1中任意字符两个字符串输入:

s1、s1

插入后的字符串输出:

#include

#include

intmain()

{

chars1[50],s2[50],s3[50],k;

inti,j,a,b,n=-1;

gets(s1);gets(s2);

a=strlen(s1);b=strlen(s2);

scanf(%c,&k);

此文档仅供学习和交流.

此文档收集于网络,如有侵权请联系网站删除for(i=0;i

{n++;

if(s1[i]==k)break;

}

for(i=0;i

s3[i]=s1[i];

for(i=n;i

s3[i]=s2[i-n];

for(i=n+b;i

s3[i]=s1[i-b];

s3[i]='\0';

puts(s3);

return0;

}

10.7YourRideIsHere

Itisawell-knownfactthatbehindeverygoodcometisaUFO.TheseUFOs

oftencometocollectloyalsupportersfromhereonEarth.Unfortunately,

theyonlyhaveroomtopickuponegroupoffollowersoneachtrip.Theydo,

however,letthegroupsknowaheadoftimewhichwillbepickedupfor

eachcometbyacleverscheme:

theypickanameforthecometwhich,along

withthenameofthegroup,canbeusedtodetermineifitisaparticular

group'sturntogo(whodoyouthinknamesthecomets?

).Thedetailsofthe

matchingschemearegivenbelow;yourjobistowriteaprogramwhich

takesthenamesofagroupandacometandthendetermineswhetherthe

groupshouldgowiththeUFObehindthatcomet.

Boththenameofthegroupandthenameofthecometareconvertedintoa

numberinthefollowingmanner:

thefinalnumberisjusttheproductofall

thelettersinthename,whereAis1andZis26.Forinstance,thegroup

USACOwouldbe21*19*1*3*15=17955.Ifthegroup'snumber

mod47isthesameasthecomet'snumbermod47,thenyouneedtotellthe

grouptogetready!

(Rememberthatamodbistheremainderleftover

afterdividingabyb;34mod10is4.)

Writeaprogramwhichreadsinthenameofthecometandthenameofthe

groupandfiguresoutwhetheraccordingtotheaboveschemethenamesare

此文档仅供学习和交流.

此文档收集于网络,如有侵权请联系网站删除amatch,printingGOiftheymatchandSTAYifnot.Thenamesofthe

groupsandthecometswillbeastringofcapitalletterswithnospacesor

punctuation,upto6characterslong.

INPUTFORMAT

Line1:

Anuppercasecharacterstringoflength1..6thatisthenameofthecomet.

Line2:

Anuppercasecharacterstringoflength1..6thatisthenameofthegroup.

COMETQ

HVNGAT

OUTPUTFORMAT

AsinglelinecontainingeitherthewordGOorthewordSTAY.

#include

#include

voidmain()

{

chara[7],b[7];

inti,pa=1,pb=1;

gets(a);

gets(b);

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

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1