1057 数零壹
Posted gzu_zb
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 }
以上是关于1057 数零壹的主要内容,如果未能解决你的问题,请参考以下文章