码迷,mamicode.com
首页 > 其他好文 > 详细

1057 数零壹

时间:2018-09-04 22:08:23      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:amp   ble   style   stream   while   链接   ems   href   ret   

题目链接: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 数零壹

标签:amp   ble   style   stream   while   链接   ems   href   ret   

原文地址:https://www.cnblogs.com/Gzu_zb/p/9588736.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!