• 文章中字符数统计


    1150 文章中字符数统计

    题目描述

    有一篇文章,共有3段文字,每段不超过1000个字符。要求统计其中英文大写字母、英文小写字母、数字的个数。

    输入描述

    /*
    输入3段文字。
    */
    Technology firm Apple has become the most valuable company in the US, with its market capitalisation overtaking that of Exxon Mobil.
    Apple had briefly become the largest US firm on Tuesday, before dropping back below the oil giant.
    But Apple has now managed to stay in the top spot at the close of Wall Street for the first time.
    

    输出描述

    /*
    输出统计结果,依次显示大写英文字母个数,小写英文字母个数,数字字符个数。
    */
    14 252 0
    
    #include<stdio.h>
    #include<string.h>
    
    int lownumber(char s[]){
        int counts =0;
        int len = strlen(s);
        int i =0;
        for(i = 0;i<len;i++){
            if(s[i]>='A'&&s[i]<='Z')
                counts++;
        }
        return counts;
    }
    
    int highnumber(char s[]){
        int counts =0;
        int len = strlen(s);
        int i =0;
        for(i = 0;i<len;i++){
            if(s[i]>='a'&&s[i]<='z')
                counts++;
        }
        return counts;
    }
    
    int numnumber(char s[]){
        int counts =0;
        int len = strlen(s);
        int i =0;
        for(i = 0;i<len;i++){
            if(s[i]>='0'&&s[i]<='9')
                counts++;
        }
        return counts;
    }
    
    int lowercasecount(char s[][1000]){
        int counts =0;
        int i =0;
        for(i = 0;i<3;i++){
            counts+= lownumber(s[i]);
        }
        return counts;
    }
    
    int highcasecount(char s[][1000]){
        int counts =0;
        int i =0;
        for(i = 0;i<3;i++){
            counts+=highnumber(s[i]);
        }
        return counts;
    }
    
    int numcount(char s[][1000]){
        int counts =0;
        int i =0;
        for(i = 0;i<3;i++){
            counts+=numnumber(s[i]);
        }
        return counts;
    }
    
    void countstr(char s[][1000]){
        int lowcase = lowercasecount(s);
        int highcase = highcasecount(s);
        int num = numcount(s);
        printf("%d %d %d
    ",lowcase,highcase,num);
    }
    
    int main()
    {
       char str[3][1000]={0};
       int i=0;
       for(i = 0;i<3;i++){
            gets(str[i]);
       }
       countstr(str);
       return 0;
    }
    
  • 相关阅读:
    C++数字与字符串相互转化
    NextDate问题
    Mac使用host屏蔽某指定网站
    Pycharm里面使用anaconda配置环境
    Logisim
    XML有关知识
    Mac环境下的Tomcat
    Allow apps downloaded from Anywhere
    寻找两数之和
    最大子序列
  • 原文地址:https://www.cnblogs.com/lwp-nicol/p/14279293.html
Copyright © 2020-2023  润新知