Description
請撰寫一個程式,接收使用者輸入的一串字串,並且輸出每個字母的出現次數。
Please write a program that receives a string input from the user and outputs the number of occurrences of each letter.
Input
輸入包含一個字串 �s,�s 的長度不會超過 6060 個字元。
The input contains a string �s. The length of �s will not exceed 6060 characters.
Output
請輸出每個字母出現的次數,若為次數為0則不顯示,由a開始輸出至z,每一個字母獨立一行。
Please output the number of times each letter appears. If the number is 0, it will not be displayed. Start outputting from a to z, with each letter on its own line.
Sample Input 1
LobsterEatsSuperDiaperWithItsHelicopter.
Sample Output 1
a:2
b:1
c:1
d:1
e:6
h:2
i:4
l:2
o:2
p:3
r:4
s:4
t:5
u:1
w:1
Sample Input 2
BeefCheeseBurgerWithExtraMeat,VegetablesAndSauce
Sample Output 2
a:5
b:3
c:2
d:1
e:12
f:1
g:2
h:2
i:1
l:1
m:1
n:1
r:3
s:3
t:4
u:2
v:1
w:1
x:1
#include <stdio.h>
int main()
{
char n[60];
char a = 'a';
int counter = 0;
scanf("%s", &n);
for(int i = 0; i<60; i++){
if(n[i]<=90 && n[i]>=65){
n[i]=n[i]+32;
}
}
for(int j=0; j<=26;j++){
counter = 0;
for(int i = 0; i<60; i++){
if(n[i]==a+j){
counter++;
}
}
if(counter>0){
printf("%c:%d\\n",a+j,counter);
}
}
return 0;
}
字母出現了幾次 (2)
Description