如果是超时,做如下修改,供参考:
#include <stdio.h>
#include <string.h>
int main()
{
int i;
char s[10001][11];
for (i = 0; i < 10001; i++)
{
scanf("%s", s[i]);
if (s[i][0] == '.') break;
}
if (i < 2)
printf("Momo... No one is for you ...");
else if (i >= 2 && i < 14)
printf("%s is the only one for you...", s[1]);
else
printf("%s and %s are inviting you to dinner...", s[1], s[13]);
return 0;
}
【以下回答由 GPT 生成】
在给定的代码中,有一些标签和属性没有正确地闭合或定义。下面是修复代码的具体建议:
<p></p>
<p class="md_img_container"><img class="md_img" src="" alt="img" align="left" /></p>
<p></p>
<p></p>
<p class="md_img_container"><img class="md_img" src="" alt="img" align="left" /></p>
<p></p>
<p></p>
<p class="md_img_container"><img class="md_img" src="" alt="img" align="left" /></p>
<br />
你需要将每个标签的开头和结束配对。此外,你还需要在<img>
标签中为src
属性提供一个有效的图片链接。
如果你还有其他问题,请随时提问。
【相关推荐】
可以使用两个字符数组分别存储第二个和第十四个人名,然后循环读取人名,当到第二个和第十四个人名时,依次读入相应字符数组,循环结束,再根据两个字符数组是否存储了人名来打印相应的结果即可。
代码如下:
参考链接:
#include <stdio.h>
#include <string.h>
int main(void){
int i=0; // 输入的字符串计数器
char name[12]; // 临时存储输入的字符串
char secondName[12]={0}; // 存储第二个人名
char fourteenthName[12]={0}; // 存储第十四个人名
scanf("%s",name); // 读取输入的字符串
i++; // 输入的字符串计数+1
// 如果输入的字符串不是'.',则进行相应判断操作
while(name!=NULL&&name[0]!='.'){
if(i==2){ // 将输入的第二个人名,存入 字符数组secondName
strcpy(secondName,name);
}
if(i==14){ // 将输入的第十四个人名,存入 fourteenthName
strcpy(fourteenthName,name);
break; //第14个以后的人名不再读入和判断
}
scanf("%s",name); // 读取下一个字符串
i++; // 读入的字符串计数+1
}
// https://blog.csdn.net/selina8921/article/details/79176297
// 根据 字符数组secondName 和 字符数组 fourteenthName 是否存储了人名,来输出对应的结果
if(strlen(secondName)!=0&&strlen(fourteenthName)!=0){
printf("%s and %s are inviting you to dinner...",secondName,fourteenthName);
}else if(strlen(secondName)!=0&&strlen(fourteenthName)==0){
printf("%s is the only one for you...",secondName);
}else if(strlen(secondName)==0&&strlen(fourteenthName)==0){
printf("Momo... No one is for you ...");
}
return 0;
}