3 solutions
-
1
题意
统计字符串中1的个数。
思路
逐位判断,是1就加进ret。
代码
#include<iostream> using namespace std; int main(){ void print(int);//输出结果 int compress(string);//压缩字符串 string input();//输入字符串 print(compress(input()));//这还需要解释? return 0; } void print(int ans){//要输出的数 cout<<ans; } int compress(string x){//要压缩的字符串 int ret(0); for(int i(0);i<8;i++)//逐位判断,锁定长为8 if(x[i]=='1') ret++; return ret; } string input(){ string ret(""); cin>>ret; return ret; }
补充
看到自己以前的人机题解了,帮我点个差评,谢~
- 1
Information
- ID
- 4658
- Time
- 1000ms
- Memory
- 250MiB
- Difficulty
- 1
- Tags
- # Submissions
- 73
- Accepted
- 43
- Uploaded By