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

cin 不能直接读入空格,可以用getline(PAT统计字符数)

时间:2017-07-23 18:23:00      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:include   line   不能   cstring   using   max   length   iostream   统计   

#include <iostream>
#include <cstring>
using namespace std;

int main(){
    string str;
    int a[200] = {0};
    
//    cin >> str;
    getline(cin, str);
    for(int i = 0; i < str.length(); i++){
        if(str[i] >= ‘a‘ && str[i] <= ‘z‘)
            a[str[i]]++;
        if(str[i] >= ‘A‘ && str[i] <= ‘Z‘)
            a[str[i] + 32]++;            
    }
    int max = 90;
    for(int i = ‘a‘; i <= ‘z‘; i++)
        if(a[max] < a[i])
            max = i;
    cout << (char)max << " " << a[max];
    return 0;
}

cin 不能直接读入空格,可以用getline(PAT统计字符数)

标签:include   line   不能   cstring   using   max   length   iostream   统计   

原文地址:http://www.cnblogs.com/zhumengdexiaobai/p/7224977.html

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