4435: 数字游戏

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:6 解决:3

题目描述

小 K 同学向小 P 同学发送了一个长度为 lns="http://www.w3.org/1998/Math/MathML">8 的 01 字符串来玩数字游戏,小 P 同学想要知道字符串中究竟有多少个 lns="http://www.w3.org/1998/Math/MathML">1

注意:01 字符串为每一个字符是 lns="http://www.w3.org/1998/Math/MathML">0 或者 lns="http://www.w3.org/1998/Math/MathML">1 的字符串,如 101 为一个长度为 lns="http://www.w3.org/1998/Math/MathML">3 的 01 字符串。

输入

输入文件只有一行,一个长度为 lns="http://www.w3.org/1998/Math/MathML">8 的 01 字符串 lns="http://www.w3.org/1998/Math/MathML">

输出

输出文件只有一行,包含一个整数,即 01 字符串中字符 lns="http://www.w3.org/1998/Math/MathML">1 的个数。

样例输入 复制

00010100

样例输出 复制

2

提示

样例 1 说明

该 01 字符串中有 lns="http://www.w3.org/1998/Math/MathML">2 个字符 lns="http://www.w3.org/1998/Math/MathML">1

样例 2 说明

该 01 字符串中有 lns="http://www.w3.org/1998/Math/MathML">8 个字符 lns="http://www.w3.org/1998/Math/MathML">1

数据规模与约定

  • 对于 lns="http://www.w3.org/1998/Math/MathML">20% 的数据,保证输入的字符全部为 lns="http://www.w3.org/1998/Math/MathML">0
  • 对于 lns="http://www.w3.org/1998/Math/MathML">100% 的数据,输入只可能包含字符 lns="http://www.w3.org/1998/Math/MathML">0 和字符 lns="http://www.w3.org/1998/Math/MathML">1,字符串长度固定为 lns="http://www.w3.org/1998/Math/MathML">8

#include<bits/stdc++.h>
using namespace std;

int main(){
    string s;
    cin>>s;
    int ans=0;
    for(auto c:s)
        if(c=='1') ans++;
    cout<<ans<<endl;
	return 0;
}