<九度 OJ>题目1098:字母统计

来源:互联网 发布:谷歌seo初级指南2016 编辑:程序博客网 时间:2024/06/06 05:40

题目描述:

输入一行字符串,计算其中A-Z大写字母出现的次数

输入:

案例可能有多组,每个案例输入为一行字符串。

输出:

对每个案例按A-Z的顺序输出其中大写字母出现的次数。

样例输入:
DFJEIWFNQLEF0395823048+_+JDLSFJDLSJFKK
样例输出:
A:0B:0C:0D:3E:2F:5G:0H:0I:1J:4K:2L:3M:0N:1O:0P:0Q:1R:0S:2T:0U:0V:0W:1X:0Y:0Z:0


#include <iostream>#include "string"#include "vector"using namespace std; bool countChar(const string &src, vector<int> &countTime);int main(){    string str;    while (cin>>str)    {        if (str.length() > 1000 || str.length() < 1)            break;        vector<int> countTime(26, 0);        countChar(str,countTime);        char a = 'A';        for (int i = 0; i < 26;i++)        {            cout << a << ":" << countTime[i] << endl;            a++;        }        str.erase();    }    return 0;} bool countChar(const string &src, vector<int> &countTime){    if (src.length() == 0)        return false;     for (unsigned int i = 0; i < src.size();i++)    {        if (src[i] >= 'A' && src[i] <= 'Z')        {            int pos = src[i] - 'A';            countTime[pos]++;        }    }    return true;}/**************************************************************    Problem: 1098    User: EbowTang    Language: C++    Result: Accepted    Time:10 ms    Memory:1520 kb****************************************************************/

注:本博文为EbowTang原创,后续可能继续更新本文。如果转载,请务必复制本条信息!

原文地址:http://blog.csdn.net/ebowtang/article/details/38374045

原作者博客:http://blog.csdn.net/ebowtang


1 0