字符统计

来源:互联网 发布:动感电子相册制作软件 编辑:程序博客网 时间:2024/06/14 15:58

字符统计1

Time Limit: 1000MS Memory Limit: 65536KB

Problem Description

给出一串字符,要求统计出里面的字母、数字、空格以及其他字符的个数。
字母:A, B, ..., Z、a, b, ..., z组成
数字:0, 1, ..., 9
空格:" "(不包括引号)
剩下的可打印字符全为其他字符。

Input

测试数据有多组。
每组数据为一行(长度不超过100000)。
数据至文件结束(EOF)为止。

Output

每组输入对应一行输出。
包括四个整数a b c d,分别代表字母、数字、空格和其他字符的个数。

Example Input

A0 ,

Example Output

1 1 1 1



#include<stdio.h>

#include<string.h>
int main(void)
{
    char str[100010];
    int i, n, x, y, z, t;


    while(gets(str) != NULL)
    {
        n = strlen(str);
        x = 0;
        y = 0;
        z = 0;
        t = 0;


       for(i = 0; i < n; i++)
       {
           if((str[i] >= 'A' && str[i] <= 'Z') || (str[i] >= 'a' && str[i] <= 'z'))
           {
               x++;
           }
          else if(str[i] >= 48 && str[i] <= 57)
          {
              y++;
          }
          else if(str[i] == ' ')
          {
              z++;
          }
          else
          {
              t++;
          }
       }
       printf("%d %d %d %d\n", x, y, z, t);
    }
    return 0;
}