1057 数零壹

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

题解:

 1 #include <iostream>
 2 #include<string>
 3 using namespace std;
 4 
 5 int main() {
 6     string str;
 7     getline(cin, str);
 8     int sum = 0, n_0 = 0, n_1 = 0;
 9     for (int i = 0; i < str.size(); i++) {
10         if ((str[i] >= 'a'&&str[i] <= 'z') || (str[i] >= 'A'&&str[i] <= 'Z')) {
11             if (str[i] >= 'a'&&str[i] <= 'z') sum += (str[i] - 'a' + 1);
12             if (str[i] >= 'A'&&str[i] <= 'Z') sum += (str[i] - 'A' + 1);
13         }
14     }
15     while (sum) {
16         if (sum % 2 == 0) n_0++;
17         else n_1++;
18         sum /= 2;
19     }
20     cout << n_0 << " " << n_1;
21     return 0;
22 }

猜你喜欢

转载自www.cnblogs.com/Gzu_zb/p/9588736.html