zoukankan      html  css  js  c++  java
  • 字符统计

    时间限制(普通/Java):1000MS/10000MS     运行内存限制:65536KByte
    总提交: 1349            测试通过: 490

    描述

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

    输入

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

    输出

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

    样例输入

     

    A0 ,
    

     

    样例输出

     

    1 1 1 1
    
    #include
    #include
    using namespace std;
    void ma(char str[100000])
    {
    long int a=0,b=0,c=0,d=0,i;
     for(i=0;;i++)
      if(str[i]=='')
       break;
      else
       if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z'))
        a++;
       else if(str[i]>='0'&&str[i]<='9')
        b++;
       else if(str[i]==' ')
        c++;
       else
        d++;
     cout<<a<<' '<<b<<' '<<c<<' '<<d<<' ';
    }
    int main()
    {
     char str[100000];
     int i;
     for(i=0;str[i]!=NULL;i++)
     gets(str);
     ma(str);
     }
     return 0;
    }
  • 相关阅读:
    Leetcode Binary Tree Paths
    Leetcode Lowest Common Ancestor of a Binary Tree
    Leetcode Lowest Common Ancestor of a Binary Search Tree
    Leetcode Path Sum
    Leetcode Symmetric Tree
    Leetcode Invert Binary Tree
    Leetcode Same Tree
    Leetcode Maximum Depth of Binary Tree
    Python Json&Pickle&模块
    Python Shelve模块
  • 原文地址:https://www.cnblogs.com/oversea201405/p/3767068.html
Copyright © 2011-2022 走看看