#include stdioh#include stringhint main char s15; int num = 0k; scanfd &k; k++; whilescanfs s!=EOF ifstrcmps End == 0 break; num++; ifk == num
#include <stdio.h> #include <string.h>
int main() { char s[15]; // 创建一个字符数组s用于存储输入的字符串 int num = 0, k; // 创建整型变量num用于计数,k用于存储输入的数字 scanf("%d", &k); // 输入一个数字并存储到变量k中 k++; // k加1,用于决定输出的位置 while (scanf("%s", s) != EOF) // 循环读取字符串,直到遇到EOF(文件结束符) { if (strcmp(s, "End") == 0) // 如果输入的字符串为"End",则跳出循环 break; num++; // 每次循环num加1 if (k == num) // 如果k等于num,则输出当前字符串 { printf("%s\n", s); num = 0; // 输出后将num重置为0 } else if (strcmp(s, "ChuiZi") == 0) // 如果输入的字符串为"ChuiZi",则输出"Bu" { printf("Bu\n"); } else if (strcmp(s, "Bu") == 0) // 如果输入的字符串为"Bu",则输出"JianDao" { printf("JianDao\n"); } else if (strcmp(s, "JianDao") == 0) // 如果输入的字符串为"JianDao",则输出"ChuiZi" { printf("ChuiZi\n"); } } return 0;
原文地址: https://www.cveoy.top/t/topic/iwHd 著作权归作者所有。请勿转载和采集!