统计大写英文字母的个数

题目描述
算算以‘.’结束的一串字符中含有多少个大写的英文字母。

输入
输入一串字符,以.结束

输出
输出一行,即这串字符中大写字母的个数。

样例输入 Copy
PRC,PRC,I’m from China.

样例输出 Copy
8

#include<iostream>
 
using namespace std;
 
int main() {
    string s;
    while(getline(cin,s)) {
        int count=0;
        for(auto &w:s) {
            if(isupper(w)) count++;
        }
        cout<<count<<endl;
    }
    return 0;
}

img

测视图:

img


代码如下:

#include<iostream>
using namespace std;

int main(){
    char s[100];
    char c;
    int sum = 0, i = 0;
    cin>>c;
    while(c != '.'){
        if(c>='A'&&c<='Z'){
            sum++;
        }
        s[i]=c;
        cin>>c;
    }
    cout<<sum;
    return 0;
}


测试图:

希望对题主有所帮助,可以的话,帮忙点个采纳!