0分求助!!!
查看原帖
0分求助!!!
1097314
封禁用户楼主2024/5/31 16:37

感觉代码没问题,样例也过了……

#include<bits/stdc++.h>
using namespace std;
int n,suma,sumb;
bool chk(int x){
	int a,b;
	while(x){
		if(x&1) a++;
		else b++;
		x/=2;
	}
	if(a>b) return true;
	else return false;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		if(chk(i)) suma++;
		else sumb++;
	}
	cout<<suma<<' '<<sumb;
}
2024/5/31 16:37
加载中...