Language:C++ 4.8.2
#include<stdio.h> #include<string.h> int main(void) { char str_original[30]; char str_guessed[30]; int arr_ori[30]; int mark[30]; // 标记数组 int n, fail_sum, success_sum, total_word; int ok; // 猜测成功与否的标志 while(1) { scanf("%d\n", &n); if(n == -1) break; memset(arr_ori, 0, sizeof(arr_ori)); memset(mark, 0, sizeof(mark)); fail_sum = success_sum = total_word = 0; scanf("%s", str_original); scanf("%s", str_guessed); int len_ori = strlen(str_original); for(int i = 0; i < len_ori; i++) { arr_ori[str_original[i] - ‘a‘] = 1; } for(int i = 0; i < 30; i++) { if(arr_ori[i]) total_word++; } int len_gue = strlen(str_guessed); int i; for(i = 0; i < len_gue; i++) { success_sum = 0; ok = 0; for(int j = 0; j < len_ori; j++) { if(str_guessed[i] == str_original[j]) { ok = 1; mark[str_guessed[i] - ‘a‘] = 1; break; } } for(int k = 0; k < 30; k++) if(mark[k]) success_sum++; if(success_sum == total_word) { printf("Round %d\nYou win.\n", n); // 去掉\n,WA break; } fail_sum += !ok; if(fail_sum == 7) { printf("Round %d\nYou lose.\n", n); break; } } if(i == len_gue) printf("Round %d\nYou chickened out.\n", n); } return 0; }
时间: 2024-11-08 18:59:13