ITP1_8_C: Counting Characters

「ITP1_8_C: Counting Characters」の編集履歴(バックアップ)一覧に戻る

ITP1_8_C: Counting Characters - (2016/03/22 (火) 09:08:51) のソース

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_8_C
文字列中の各アルファベットの個数をこたえる問題。

 #include <iostream>
 #include <stdio.h>
 #include <ctype.h>
 
 using namespace std;
 
 int main() 
 {
	// your code goes here
	
	int counts[30]={0};
	
	char cs[1201];
	while(scanf("%[^\n]\n",cs)!=EOF){
		for(int i=0;cs[i]!='\0';i++){
			if(isalpha(cs[i])){
				counts[tolower(cs[i])-'a']++;
			}
		}
	}
 
	for(char c='a';c<='z';c++){
		printf("%c : %d\n",c,counts[c-'a']);
	}
	return 0;
 }