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


  • 相关阅读:
    java序列化进阶
    jQuery学习一(选择器)
    java poi 操作Excel常用方法总结
    mybatis批量foreach的使用
    java中关于try、catch、finally的总结
    MyEclipse使用指南(精简版)
    单例模式
    抽象工厂模式
    java.io.Serializable
    java.lang.string
  • 原文地址:https://www.cnblogs.com/yldf/p/6249938.html
Copyright © 2011-2022 走看看