提交时间:2024-08-19 16:17:26

运行 ID: 167288

#include <bits/stdc++.h> using namespace std; int main() { freopen("classify.in","r",stdin); freopen("classify.out","w",stdout); int j,a,b,mod,ta=0,tb=0,x,y; //使用j来处理,不影响程序;mod提取判断;ta和tb统计,a和b则统计具体数里0和1的个数 cin>>x>>y; for(; x<=y; x++)//逐个扫描 { j=x,a=0,b=0; while(j)//数的判断 { mod=j%2; j>>=1;//右移,代替除以二 if(mod)//如果是一 a++;//a加一 else//否则 b++;//b加一 } if(a>b)//比较 ta++; else tb++; } cout<<ta<<' '<<tb; return 0; }