题目1098:字母统计

来源:互联网 发布:voip软件电话 编辑:程序博客网 时间:2024/06/14 00:49
题目描述:

输入一行字符串,计算其中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:0

Z:0

#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std; const int maxn=26;const int maxl=1000;int t[maxn];char s[maxl];int main(){    while(scanf("%s",s)!=EOF)    {        memset(t,0,sizeof(t));        for(int i=0;i<strlen(s);i++)            if((s[i]>='A')&&(s[i]<='Z'))            t[s[i]-'A']++;        for(int i=0;i<maxn;i++)            printf("%c:%d\n",'A'+i,t[i]);    }    return 0;}


0 0