
字符统计
Time Limit: 1 Sec Memory Limit: 64 MB
Submit: 421 Solved: 92
[Submit][Status][Web Board]
Description
给出一串字符,要求统计出里面的字母、数字、空格以及其他字符的个数。字母:A, B, ..., Z、a, b, ..., z组成数字:0, 1, ..., 9 空格:" "(不包括引号) 剩下的可打印字符全为其他字符。
Input
测试数据有多组。每组数据为一行(长度不超过100000)。数据至文件结束(EOF)为止。
Output
每组输入对应一行输出。包括四个整数a b c d,分别代表字母、数字、空格和其他字符的个数。
Sample Input
A0 ,
Sample Output
1 1 1 1
HINT
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
char s[];
int main()
{
while( cin.getline(s,,'\n')){
int a=,b=,c=,d=;
for(int i=;s[i]!='\0';i++){
if( ('a'<=s[i] && s[i]<='z') || ('A'<=s[i] && s[i]<='Z') )
a++;
else if( ''<=s[i] && s[i]<='' )
b++;
else if( s[i]==' ' )
c++;
else
d++;
}
cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
}
return ;
}
Freecode : www.cnblogs.com/yym2013