zoukankan      html  css  js  c++  java
  • C++找出其中的大写字母、小写字母、空格、数字以及其他字符各有多少

    C++找出其中的大写字母、小写字母、空格、数字以及其他字符各有多少

    任务描述

    输入一行文字,找出其中的大写字母、小写字母、空格、数字以及其他字符各有多少(要求用指针或引用方法处理)。

    测试输入:

    abcJK 116_
    

    预期输出:

    upper case:2
    lower case:3
    space:1
    digit:3
    other:1
    

    测试输入:

    QWERzxcv@#$7 8*(zz
    

    预期输出:

    upper case:4
    lower case:6
    space:1
    digit:2
    other:5
    

    源代码:

    #include <stdio.h>
    #include <iostream>
    #include <string.h>
    using namespace std;
    
    
    int main()
    {
        string str;
        int lowersum=0,uppersum=0,space=0,digitsum=0,othersum=0;
        int i;
        getline(cin,str);
        for(i=0;i<str.length();i++){
            if(str[i]>='a'&&str[i]<='z')lowersum++;
            else if(str[i]>='A'&&str[i]<='Z')uppersum++;
            else if(str[i]==' ')space++;
            else if(str[i]>='0'&&str[i]<='9')digitsum++;
            else othersum++;
        }
        cout<<"upper case:"<<uppersum<<endl;
        cout<<"lower case:"<<lowersum<<endl;
        cout<<"space:"<<space<<endl;
        cout<<"digit:"<<digitsum<<endl;
        cout<<"other:"<<othersum<<endl;
        return 0;
    }
    
  • 相关阅读:
    移动端页面滚动性能调优
    外盘期货交易安全吗
    Vuetify的pagination功能踩坑
    oh-my-zsh自定义主题
    SSM整合
    Spring底层学习 1
    Node.js+Express day01
    JS+DOM conclusions
    tables+form+validation+Semantic HTML
    mybatis-利用association和collection实现一对一和一对多
  • 原文地址:https://www.cnblogs.com/lightice/p/12691758.html
Copyright © 2011-2022 走看看