怎样改才能符合要求,输出总是不对
毕业设计
1
#include<stdio.h> //以上是朋友圈中一奇葩贴:“2月14情人节了,我决定造福大家。第2个赞和第14个赞的,我介绍你俩认
识…………咱三吃饭…你俩请…”。现给出此贴下点赞的朋友名单,请你找出那两位要请客的倒霉蛋
int main() //输入格式:
输入按照点赞的先后顺序给出不知道多少个点赞的人名,每个人名占一行,为不超过10个英文字母的非空
单词,以回车结束。一个英文句点.标志输入的结束,这个符号不算在点赞名单里。
//输出格式:
根据点赞情况在一行中输出结论:若存在第2个人A和第14个人B,则输出“A and B are inviting you to dinner...”;
若只有A没有B,则输出“A is the only one for you...”;若连A都没有,则输出“Momo... No one is for you ...”。
{
char c,s1,s2;
int i=0;
while(1)
{
scanf("%s",&c);
i++;
if(c=='.')
{
break;
}
if(i==2) s1=c;
if(i==12) s2=c;
}
if(i>=12) printf("%s and %s are inviting you to dinner...\n",s1,s2);
else if(i>=2&&i<12) printf("%s is the only one for you...\n",s1);
else printf("Momo... No one is for you ...");
return 0;
-
供参考:
#include <stdio.h> #include <string.h> int main() { char c[11], s1[11] = { 0 }, s2[11] = {0};//每个人名为不超过10个英文字母的非空单词 int i = 0; while (1) { scanf("%s", c); if (strcmp(c, ".") == 0) break; i++; if (i == 2) strcpy(s1, c);//第2个赞 if (i == 14) strcpy(s2, c);//第14个赞 } if (i >= 14) printf("%s and %s are inviting you to dinner...\n", s1, s2); else if (i >= 2 && i < 14) printf("%s is the only one for you...\n", s1); else if (i < 2) printf("Momo... No one is for you ..."); return 0; }
-
#include<stdio.h> #include<string.h> int main() { //人名要用字符数组接收 char s1[12],s2[12],c[12]; int i=0; while(1) { scanf("%s",&c); //字符数组不能直接用==比较 if(strcmp(c,".")==0) { break; } //最后的.不计入人数 i++; //字符数组不能直接用=赋值 if(i==2) strcpy(s1,c); if(i==14) strcpy(s2,c); } if(i>=14) printf("%s and %s are inviting you to dinner...\n",s1,s2); else if(i>=2&&i<14) printf("%s is the only one for you...\n",s1); else printf("Momo... No one is for you ..."); return 0; }
发表回复