zoukankan      html  css  js  c++  java
  • 统计字符串中的字母,数字,空格和其它字符.

    #include<stdio.h>
    #include<ctype.h>
    int main()
    {
        int i=0;
        char str[]="abc 123 %&def";
        int other=0,blank=0,alpha=0,digital=0;
        while(str[i])
        {
            if(isalpha(str[i])) //判断是否是字母
            {
                alpha++;
            }
            else if(isblank(str[i]))//判断是否是空格
            {
                blank++;
            }
            else if(isdigit(str[i]))//判断是否是数字
            {
                digital++;
            }
            else
                other++;      //其它字符
                i++;
        }
        printf("字母是%d个 ",alpha);
        printf("数字是%d个 ",digital);
        printf("空格是%d个 ",blank);
        printf("其他是%d个 ",other);
        return 0;
    }



  • 相关阅读:
    I
    D
    K
    G
    J
    Doom HDU
    Mountaineers Gym
    华南理工大学“三七互娱杯”程序设计竞赛(重现赛)( HRY and array 高精度除法模板)
    Corn Fields POJ
    linux如何安装缺失依赖
  • 原文地址:https://www.cnblogs.com/wuzhang/p/wuzhang6.html
Copyright © 2011-2022 走看看