中国石油大学C语言答案 联系客服

发布时间 : 星期三 文章中国石油大学C语言答案更新完毕开始阅读6cfe4d520b4c2e3f56276343

} m=strlen(s2); n=strlen(s1); for(i=0; i

for(i=c; i

for(i=c+m; i<=m+n; i++) s3[i]=s1[i-m]; puts(s3); }

8.7 Your Ride Is Here

It is a well-known fact that behind every good comet is a UFO. These UFOs often come to collect loyal supporters from here on Earth. Unfortunately, they only have room to pick up one group of followers on each trip. They do, however, let the groups know ahead of time which will be picked up for each comet by a clever scheme: they pick a name for the comet which, along with the name of the group, can be used to determine if it is a

particular group's turn to go (who do you think names the comets?). The details of the matching scheme are given below; your job is to write a program which takes the names of a group and a comet and then determines whether the group should go with the UFO behind that comet.

Both the name of the group and the name of the comet are converted into a number in the following manner: the final number is just the product of all the letters in the name, where \= 17955. If the group's number mod 47 is the same as the comet's number mod 47, then you need to tell the group to get ready! (Remember that \over after dividing a by b; 34 mod 10 is 4.)

Write a program which reads in the name of the comet and the name of the group and figures out whether according to the above scheme the names are a match, printing \if they match and \of capital letters with no spaces or punctuation, up to 6 characters long. INPUT FORMAT

Line 1: An upper case character string of length 1..6 that is the name of the comet. Line 2: An upper case character string of length 1..6 that is the name of the group.

OUTPUT FORMAT

A single line containing either the word \#include #include int main() { char s1[7],s2[7];int i,j=1,k=1; gets(s1); gets(s2);

for(i=0;s1[i]!='\\0';i++) { s1[i]=s1[i]-'A'+1; j=s1[i]*j; }

for(i=0;s2[i]!='\\0';i++) {

s2[i]=s2[i]-'A'+1; k=k*s2[i]; } if(jG==kG) printf(\ else printf(\}

8.8大数相加 问题描述:

编写C程序,它能以字符串形式读入两个无符号正整数m和n,计算并输出这两个整数之和

输入格式:

输入由两行组成,第一行为无符号整数m,第二行为无符号整数n,且m和n的值最长25位

输出格式:

输出为一行,即两个无符号整数m和n之和 输入样例: 9999888888 355729288 输出样例: 10355618176

#include #include #include int main() {

int i,j,k,t,a[27]={0},b[27]={0},c[27]={0}; char m[26],n[26]; gets(m); gets(n); i=strlen(m); j=strlen(n);

for(k=i-1,t=0;k>=0;k--,t++) a[t]=m[k]-'0';

for(k=j-1,t=0;k>=0;k--,t++)

b[t]=n[k]-'0'; for(k=0;k<=26;k++) {

c[k]=c[k]+a[k]+b[k]; if(c[k]>=10) {

c[k]=c[k]-10; c[k+1]=1; } }

for(k=26;k>=0;k--) if(c[k]>0)break; for(k=k;k>=0;k--) printf(\ printf(\ return 0; }

8.9 字符串重排列

判断一个字符串是否可以由另一个字符串通过重排字符而得到。注意,此处区分字符大小写! 输入

输入只有一行,为两个字符串,字符串之间以一个空格分隔。 输出

如果两个字符串由同一组字符组成(且每一个字符出现次数相同),则输出“YES”; 否则输出“NO”。注意YES和NO都是大写字母! #include int main() { int i,j,flag=0,count=0;char a[10],b[10]; scanf(\ for(i=0;a[i]!='\\0';i++) count++; for(i=0;a[i]!='\\0';i++) for(j=0;b[j]!='\\0';j++) if(a[i]==b[j]||a[i]==b[j]+'a'-'A'||a[i]+'a'-'A'==b[j]) { flag++; b[j]='0'; break; } if(flag==count) printf(\ else printf(\}

8.10上课啦!要点名啊!

小凡的老师每次上课前都要点名,但是这样就浪费了老师的上课时间。所以老师让小凡来完成点名,让小凡在早自习的时候就点好名。老师给了小凡名单,小凡只要照着名单点名就好了是不是很简单啊。 输入

输入有多组数据,直到文件结束。每组测试数据有三行,第一行为两个整数m, n(50 >= m >= n)。第二行有m个名字,名字之间用空格隔开,是小凡班上同学的名单。后面有n个名字是来上课的同学。名字间用空格隔开。名字的长度不超过20个字符。 输出

按照第一行的名单,每个人对应输出是否到了。到的人输出Yes,没到的人输出No。 #include int main() {

int m,n,i,j;

char a[51][21],b[51][21]; scanf(\ for(i=0;i

scanf(\ for(i=0;i

for(j=0;j

if(strcmp(a[i],b[j])==0) {

printf(\ break; } }

if(j==n)printf(\ } }

8.11找第一个只出现一次的字符 问题描述:

给定t个字符串,这个字符串只可能由26个小写字母组成,请你找到第一个仅出现一次的字符,如果没有符合要求的字符,就输出no。 输入:

第一行是t,接下来是t个字符串,每个字符串长度小于100 输出:

你的输出需要由t行组成。

对于每个字符串,输出第一个仅出现一次的字符,没有输出NO。 输入样例: