HDU1860 统计字符

问题链接HDU1860 统计字符

问题简述:参见上述链接。

问题分析

  这是一个有关字符串处理的问题。

程序说明

  函数getline()用在这里正合适。

AC的C++语言程序如下:

/* HDU1860 统计字符 */

#include <iostream>
#include <string>

using namespace std;

const string END = "#";

int main()
{
    string character, s;
    int count;

    while(getline(cin, character)) {
        if(character == END)
            break;

        getline(cin, s);

        for(int i=0; i<(int)character.size(); i++) {
            count = 0;
            for(int j=0; j<(int)s.size(); j++)
                if(s[j] == character[i])
                    count++;
            cout << character[i] << " " << count << endl;
        }
    }
    return 0;
}



posted on 2017-04-05 18:57  海岛Blog  阅读(147)  评论(0编辑  收藏  举报

导航