Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
157884 格林老师 二进制数问题 C++ Accepted 1 MS 264 KB 657 2026-08-18 18:06:10

Tests(1/1):


Code:

#include <bits/stdc++.h> using namespace std; int main() { int A=0,B=0; for (int i=1;i<=1000;i++){ int num=i; string s=""; while (num>0){ s=s+char(num%2+'0'); //是否可以用string类型 num/=2; } reverse(s.begin(),s.end()); int s0=0,s1=0; for (int j=0;j<s.length();j++){ if (s[j]=='0'){ s0++; } else{ s1++; } } if (s1>s0){ A++; } else{ B++; } } cout<<A<<" "<<B<<endl; return 0; }