ITP1_8_C: Counting Characters

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;
}
最終更新:2016年03月22日 09:08