PAT 乙级 1057

题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805270914383872

#include <stdio.h>
#include <ctype.h>

int main() {
    int sum = 0;
    char c;
    while((c = getchar()) != '\n') {
        if (isalpha(c)) {
            c = tolower(c);
            sum += c - 'a' + 1;
        }
    }
    int cnt_0 = 0, cnt_1 = 0;
    while (sum != 0) {
        if (sum % 2 == 0) {
            cnt_0++;
        } else {
            cnt_1++;
        }
        sum /= 2;
    }
    printf("%d %d\n", cnt_0, cnt_1);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41932111/article/details/87720912