zoukankan      html  css  js  c++  java
  • 统计字母数字等个数

    Problem Description

    输入一串字符,统计这串字符里的字母个数,数字个数,空格字数以及其他字符(最多不超过100个字符)

    Input

    多组测试数据,每行一组

    Output

    每组输出一行,分别是字母个数,数字个数,空格字数以及其他字符个数

    Sample Input

    I am a student in class 1.
    I think I can!

    Sample Output

    18 1 6 1
    10 0 3 1
    




    源代码如下:

    #include <iostream>
    #include<cctype>
    using namespace std;

     char s[100];
    int main()
    {
        int alpha,num,space,other;
       while(gets(s))
       {
           alpha=0,num=0,space=0,other=0;
           for(int i=0;s[i]!='';++i)
           {
               if(isalpha(s[i]))      ++alpha;
               else if(isdigit(s[i])) ++num;
               else if(s[i]==32)      ++space;
               else                   ++other;
           }
           cout<<alpha<<" "<<num<<" "<<space<<" "<<other<<endl;
       }
        return 0;
    }


  • 相关阅读:
    gcvt(),ecvt(),fcvt()的区别
    SQLITE3 使用总结
    C++的类型转换浅析
    JAVA Class21
    JAVA Class20
    JAVA Class19
    JAVA Class18
    JAVA Class17
    JAVA Class16
    关于hover失效问题(!important)
  • 原文地址:https://www.cnblogs.com/yldf/p/11900207.html
Copyright © 2011-2022 走看看