知识点:
复合类型:
字符/字符数组。
#include <cstdio> #include <cstring> #include <iostream> using namespace std; int main() { int a_count = 0; int b_count = 0; char votes[100]; scanf("%s", votes); int len = strlen(votes); for (int i = 0; i < len - 1; i++) { if (votes[i] == 'A') { a_count++; } else { b_count++; } } if (a_count == b_count) { printf("E\n"); } else if (a_count > b_count) { printf("A\n"); } else { printf("B\n"); } return 0; } /* int main() { char str[20]; char ch; int i = 0; int a = 0; int b = 0; while ((ch = getchar()) != '0') { str[i] = ch; i++; } str[i] = '\0'; // printf("%s", str); for (int i = 0; str[i] != '\0'; i++) { if (str[i] == 'A') { a++; } else { b++; } } if (a > b) { printf("A"); } else if (a < b) { printf("B"); } else { printf("E"); } } */