#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main() { int i; //用于循环 int k; //表示平局的间隔次数 int index; //标记平局次数 char name[20]; //输入出招名字 scanf("%d",&k); index=k; //标记住间隔次数 while(1) { scanf("%s",name); if(strcmp(name,"End")==0) break; else { if(index==0) { if(strcmp(name,"ChuiZi")==0) printf("ChuiZi\n"); if(strcmp(name,"JianDao")==0) printf("JianDao\n"); if(strcmp(name,"Bu")==0) printf("Bu\n"); index = k; } else { if(strcmp(name,"ChuiZi")==0) printf("Bu\n"); if(strcmp(name,"JianDao")==0) printf("ChuiZi\n"); if(strcmp(name,"Bu")==0) printf("JianDao\n"); index--; //每赢一次,间隔次数就少了1,当=0时,要平局 } } } return 0; }
#include<stdio.h> #include<ctype.h> //判断是否为空格or非字母非数字字符 int Judge(char p) { if ((p >= 'A' && p <= 'Z') || (p >= 'a' && p <= 'z') || (p >= '0' && p <= '9')) { return 0; } else { return 1; } } //去除空格 void DelBlank(char arr[], int len) { int i = 0; for (i = 0; i < len; i++) { //处理开头的空格 if (arr[0] == ' ') { int j = 0; for (j = 0; j < len; j++) { arr[j] = arr[j + 1]; } } if (arr[i] == ' ') { int flag = Judge(arr[i + 1]); if (flag == 1) { int k = 0; for (k = i; k < len; k++) { arr[k] = arr[k + 1]; } i--; } } } } //大写转小写 void Tolower(char arr[], int len) { int i = 0; for (i = 0; i < len; i++) { if (arr[i] != 'I') { arr[i] = tolower(arr[i]); } } } //替换并打印最终结果 void ReplacePrint(char arr[]) { printf("AI: "); int i = 0; for (i = 0; i < strlen(arr); i++) { if ((arr[i] == 'c' && arr[i + 1] == 'a' && arr[i + 2] == 'n' && arr[i + 3] == ' ' && arr[i + 4] == 'y' && arr[i + 5] == 'o' && arr[i + 6] == 'u') && (i == 0 || arr[i - 1] == ' ') && (arr[i + 7] == ' ' || arr[i + 7] == '\0' || Judge(arr[i + 7]))) { printf("I can"); i += 6; } else if ((arr[i] == 'c' && arr[i + 1] == 'o' && arr[i + 2] == 'u' && arr[i + 3] == 'l' && arr[i + 4] == 'd' && arr[i + 5] == ' ' && arr[i + 6] == 'y' && arr[i + 7] == 'o' && arr[i + 8] == 'u') && (i == 0 || arr[i - 1] == ' ') && (arr[i + 9] == ' ' || arr[i + 9] == '\0' || Judge(arr[i + 9]))) { printf("I could"); i += 8; } else if (arr[i] == 'I' && (i == 0 || arr[i - 1] == ' ') && (arr[i + 1] == ' ' || arr[i + 1] == '\0' || Judge(arr[i + 1]))) { printf("you"); } else if ((arr[i] == 'm' && arr[i + 1] == 'e') && (i == 0 || arr[i - 1] == ' ') && (arr[i + 2] == ' ' || arr[i + 2] == '\0' || Judge(arr[i + 2]))) { printf("you"); i += 1; } else { printf("%c", arr[i]); } } } void Change(char arr[], int len) { int i = 0; for (i = 0; i < len; i++) { if (arr[i] == '?') { arr[i] = '!'; } } } int main() { int n = 0; scanf("%d", &n); getchar(); char arr[1001] = { 0 }; int i = 0; for (i = 0; i < n; i++) { gets(arr); printf("%s\n", arr); int len = strlen(arr); DelBlank(arr, len); Tolower(arr, len); Change(arr, len); ReplacePrint(arr); printf("\n"); } return 0; }
标签:8.1,index,name,int,printf,include,strcmp From: https://www.cnblogs.com/xuxingkai/p/17599136.html