华为OJ——统计大写字母个数

    xiaoxiao2025-04-29  8

    统计大写字母个数

    题目描述

    找出给定字符串中大写字符('A'-'Z')的个数

    接口说明

    原型:int CalcCapital(String str);

    返回值:int

    输入描述:

    输入一个String数据

    输出描述:

    输出string中大写字母的个数

    输入例子:

    add123#$%#%#O

    输出例子:

    1

    解答代码:

    #include<iostream> #include<fstream> #include<string> #include<cstring> #include<algorithm> #include<sstream> using namespace std; int main() { //freopen("1.txt","r",stdin); string words; int i,count; while(cin>>words) { count=0; int length=words.length(); for(i=0; i<length; i++) { if(words[i]>='A' && words[i]<='Z') count++; } cout<<count<<endl; } return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-1298569.html
    最新回复(0)