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

题目描述:

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

输入:

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

输出:

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

样例输入:
DFJEIWFNQLEF0395823048+_+JDLSFJDLSJFKK
样例输出:
A:0
B:0
C:0
D:3
E:2
F:5
G:0
H:0
I:1
J:4
K:2
L:3
M:0
N:1
O:0
P:0
Q:1
R:0
S:2
T:0
U:0
V:0
W:1
X:0
Y:0
Z: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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值