// PATn.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
int chr_to_int(char c)
{
c = tolower(c);
return (c - 'a' + 1);
}
int main()
{
string s;
getline(cin, s);//题目要求以回车结束字符串,所以不能使用cin>>s形式!
int sum = 0;
for (auto &r : s)
{
if(isalpha(r))
sum = sum + chr_to_int(r);
}
unsigned count_0 = 0, count_1 = 0;
unsigned r=sum;
while (r != 0)
{
auto tmp = r % 2;
if (tmp == 0)
{
count_0 += 1;
}
else
{
count_1 += 1;
}
r = r / 2;
}
cout << count_0 << " " << count_1;
system("pause");
return 0;
}
网友评论