ytu 1910:字符统计(水题)

字符统计

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

 1 #include <iostream>
 2 #include <string>
 3 #include <stdio.h>
 4 using namespace std;
 5 char s[10001];
 6 int main()
 7 {
 8     while( cin.getline(s,10001,'
')){
 9         int a=0,b=0,c=0,d=0;
10         for(int i=0;s[i]!='';i++){
11             if( ('a'<=s[i] && s[i]<='z') || ('A'<=s[i] && s[i]<='Z') )
12                 a++;
13             else if( '0'<=s[i] && s[i]<='9' )
14                 b++;
15             else if( s[i]==' ' )
16                 c++;
17             else
18                 d++;
19         }
20         cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
21     }
22     return 0;
23 }

Freecode : www.cnblogs.com/yym2013

原文地址:https://www.cnblogs.com/yym2013/p/3460314.html