zoukankan      html  css  js  c++  java
  • 文章中字符数统计

    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;
    }
    
  • 相关阅读:
    数据结构学习笔记(特殊的线性表:栈与队列)
    数据结构学习笔记(线性表)
    使用U盘安装 OS X 的坑
    chrome插件推荐
    Mac下安装oh-my-zsh
    sublime下让代码居中
    Mac上关于shell使用Python3和C++11声明
    github学习(三)
    github学习(二)
    github学习(一)
  • 原文地址:https://www.cnblogs.com/lwp-nicol/p/14279293.html
Copyright © 2011-2022 走看看