提交时间:2024-08-19 20:13:30

运行 ID: 167888

#include<iostream> #include<string> #include<bitset> using namespace std; int main(){ int a,b,s1,s2,A=0,B=0; string s; cin>>a>>b; for(int i = a; i <= b; i++){ bitset<32> b(i); s = b.to_string(); s1 = 0;s2 = 0; while(s.front() == '0'){ s.erase(s.begin()); } for(char c : s){ if(c == '1'){ s2++; } else if(c == '0'){ s1++; } } if(s2 > s1){ A++; }else{ B++; } } cout<<A<<' '<<B; return 0; }