1500. 统计字母个数

时间限制:1Sec内存限制:128MB通过:118提交:267

题目描述

给定一段文章,请输出每个字母出现的次数。

输入

只有一组输入数据,该组数据大小<10KB,文章中可能包含大写字母或者其他不是字母的字符,要求只统计出现的小写字母的次数,文章以’#'结尾。

输出

输出格式为"C A",C为’a’…'z’中的字母,A为出现的次数,C和A之间以一个空格隔开,每个字母组输出占一行。

样例输入

here is the input
this is the article#

样例输出

a 1
b 0
c 1
d 0
e 5
f 0
g 0
h 4
i 5
j 0
k 0
l 1
m 0
n 1
o 0
p 1
q 0
r 2
s 3
t 5
u 1
v 0
w 0
x 0
y 0
z 0

#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a[10005];
    int b[10005]={0},s=0,s1=0,flag=0;
    while(1)
    {gets(a);
        int len;
        len=strlen(a);
        for(int i=0;i<len;i++)
        {
            if(a[i]=='#')
            {
                flag=1;
                break;
            }
            if(a[i]>='a'&&a[i]<='z')
            {
                b[a[i]-'a']+=1;
            }
        }
        if(flag==1)
        {
            break;
        }

    }
        char a1='a';
        for(int i=0;i<26;i++)
        {
            cout<<a1<<" "<<b[i]<<endl;
            a1+=1;
        }
}

猜你喜欢

转载自blog.csdn.net/weixin_52908342/article/details/119877805
今日推荐