Sumo and Keyboard-Cat

SumoandKeyboard-Cat

https://ac.nowcoder.com/acm/problem/207570

题目:Sumo and Keyboard-Cat
来源:第十七届浙大城市学院程序设计竞赛(同步赛)

解题思路

求出字符串的大小写转换的次数,初始为大写。

C++代码

#include<iostream>
using namespace std;

int main(){
    string s;
    cin >> s;
    bool flag = true;
    int cnt = 0;
    for(int i=0; i<s.size(); ++i){
        if(flag && s[i]>='a' && s[i] <='z'){
            ++cnt;
            flag = false;
        }
        else if(!flag && s[i]>='A' && s[i]<='Z'){
            ++cnt;
            flag = true;
        }
    }
    cout << cnt << endl;
    return 0;
}
全部评论

相关推荐

牛客83700679...:简历抄别人的,然后再投,有反馈就是简历不行,没反馈就是学历不行,多投多改只要技术不差机会总会有的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务