我的个人网站 Cheese的个人主页http://www.cheese.ren/
博客来源 PAT 乙级 1057 数零壹-Cheese的个人博客PAT 乙级 1057 数零壹http://blog.cheese.ren/77
欢迎交换友链 :-)
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
getline(cin, str);
// caculate the sum
int sum=0;
for (int i=0; i<str.length(); i++) {
// if the char ranges from 'A' to 'Z'
if (str[i] >= 'A' && str[i] <= 'Z')
sum += str[i] - 'A' + 1;
// if the char ranges from 'a' to 'z'
else if (str[i] >= 'a' && str[i] <= 'z')
sum += str[i] - 'a' + 1;
}
// caculate the binary
int one_count=0, zero_count=0;
while (sum) {
if (sum % 2 == 0)
zero_count++;
else if (sum % 2 == 1)
one_count++;
sum /= 2;
}
printf("%d %d\n", zero_count, one_count);
return 0;
}