题解 | #竞选社长#
竞选社长
https://www.nowcoder.com/practice/45a30e3ef51040ed8a7674984d6d1553
#include <stdio.h> #include <string.h> int main() { char arr[1000]; while (scanf("%s", arr) != EOF) { // 注意 while 处理多个 case // 64 位输出请用 printf("%lld") to int countA = 0; int countB = 0; int sz = strlen(arr); int i; //找出A,B并计数 for(i = 0; i< sz; i++) { if(arr[i] == 'A') { countA++; } else if(arr[i] == 'B') { countB++; } } //打印 if (countA > countB) { printf("A\n"); } else if(countA == countB) { printf("E\n"); } else { printf("B\n"); } } return 0; }
笨小猴写完之后这个显得得心应手