题目描述
给定一段文章,请输出每个小写字母出现的次数
输入格式
只有一组输入数据,该数据大小<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>
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
//freopen("/config/workspace/test/test","r",stdin);
string s;
int flag=0;
int a[26]={0};
while(cin>>s){
if(s[s.length()-1]=='#') flag=1;
for(int i=0;i<s.length();i++){
if(s[i]>='a'&&s[i]<='z'){
int k=s[i]-'a';
a[k]++;
}
}
if(flag==1) break;
}
char ch;
for(int i=0;i<26;i++){
ch=i+'a';
cout<<ch<<" "<<a[i]<<endl;
}
return 0;
}
//闲叙题外话:“不想呵其实强:你撇下半天风韵,我拾得万种思量。”