题解 | 小红的01串

小红的01串

https://www.nowcoder.com/practice/8920f77fb2c0409a9f4f9025969110de

经分析发现,仅当‘1’与‘0’的数量均为奇数时无法使所有字符相等。

#include <iostream>
#include<string>
using namespace std;

void solve(){
    string s;
    cin>>s;
    int c1=0,c0=0;
    for(char c:s){
        if(c=='1')c1++;
        else c0++;
    }
    if(c1%2&&c0%2)cout<<"No\n";
    else cout<<"Yes\n";
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--)solve();
    return 0;
}

全部评论

相关推荐

03-10 11:23
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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