P5660 [CSP-J2019] 数字游戏 题解

简单模拟题,循环统计 11 的个数即可,注意下标从 00 开始。

#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int ans = 0;
    cin >> s;
    for(int i = 0; i < 8; i ++){
        if(s[i] == '1') ans ++;
    }
    cout << ans;
}

posted on 2024-12-22 19:41  zhangzirui66  阅读(18)  评论(0)    收藏  举报  来源

导航