题解 | #竞选社长#

竞选社长

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");
    }

}
*/

全部评论

相关推荐

10-16 15:48
算法工程师
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务