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



  • 相关阅读:
    完美世界笔试(动态规划,背包问题)
    腾讯笔试3
    腾讯笔试2
    腾讯笔试1
    阿里笔试1
    Merge Sorted Array
    Partition List
    Reverse Linked List II
    Remove Duplicates from Sorted List II
    白菜刷LeetCode记-704. Binary Search
  • 原文地址:https://www.cnblogs.com/wuzhang/p/wuzhang6.html
Copyright © 2011-2022 走看看