题目描述
给定一段文章,请输出每个小写字母出现的次数
输入格式
只有一组输入数据,该数据大小<10KB。该文章包括大小写字母、数字、标点符号等。文章以’#’结尾。
输出格式
输出格式为“C A”,C为’a’..’z’中的字母,A为出现次数,C和A之间空一格
样例输入content_copy
here is the input
this is the article#
样例输出content_copy
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
import java.util.Scanner;
public class Main {
public static void main(String[] arge) {
Scanner scan=new Scanner(System.in);
boolean finish=false;
int[] count=new int['z'-'a'+1];
while(!finish) {
String line=scan.nextLine();
for(int i=0;i<line.length();i++) {
char c=line.charAt(i);
if(c=='#') {
finish=true;
break;
}
if('a'<=c&&c<='z')
count[c-'a']++;
}
}
for(int i=0;i<count.length;i++)
System.out.println((char)(i+'a')+" "+count[i]);
}
}
315

被折叠的 条评论
为什么被折叠?



