题解 | #竞选社长#
竞选社长
https://www.nowcoder.com/practice/45a30e3ef51040ed8a7674984d6d1553
知识点:
复合类型:
字符/字符数组。
#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");
}
}
*/
拼多多集团-PDD公司福利 817人发布
查看1道真题和解析