题目名字
数字游戏
题目链接
https://www.luogu.com.cn/problem/P5660
题意
一个长度为 8 的 01 字符串,想要知道字符串中究竟有多少个 1
思路
- for 循环找到
时间复杂度
入门
代码
#include <iostream>
#include <string.h>
using namespace std;
int main() {
string a;
int count;
cin>>a;
for(int i=0;i<8;i++){
if(a[i]=='1'){
count++;
}
}
cout<<count;
return 0;
}