表题统计

1、学习了getline(cin,str)库函数的使用

2、学习使用了打表法

1、题目:要求统计字符串中大写字母、小写字母、数字的个数

#include<iostream>
#include<cstring>
#include<ctype.h>

using namespace std;

int main()
{
    int ans=0;
    string s;
    getline(cin,s);
    for(int i=0;i<s.size();i++)
    {
        if(isupper(s[i]) || islower(s[i]) || isdigit(s[i]))
        {
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

getline的功能是由键盘向字符数组中添加元素

ctype库函数中的isupper用来识别大写英文字母,islower用来识别小写英文字母,isdigit用来识别数字

posted @ 2020-10-05 23:20  侯志远!!!  阅读(77)  评论(0)    收藏  举报