1057

作者: 峡迩 | 来源:发表于2017-09-04 21:52 被阅读0次
    // 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;
    }
    
    

    相关文章

      网友评论

          本文标题:1057

          本文链接:https://www.haomeiwen.com/subject/khryjxtx.html