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;
    }


  • 相关阅读:
    UVA 439 Knight Moves
    UVA 673 Parentheses Balance
    UVa 536 Tree Recovery
    UVA 712 S-Trees
    UVA 12657 Boxes in a Line
    UVA 679 Dropping Balls
    UVA 1603 Square Destroyer
    UVA 1343 The Rotation Game
    UVA 1374 Power Calculus
    UVA 12558 Egyptian Fractions (HARD version)
  • 原文地址:https://www.cnblogs.com/yldf/p/11900207.html
Copyright © 2011-2022 走看看