#include <iostream>
#include <bitset>
using namespace std;
int main() {
int n = 0;
while (cin>>n){
bitset<32> s(n);
if(n==0){
cout<<"NO"<<endl;
continue;
}
int odd=0;
int even=0;
for (int i=0; i<32; i+=2)
{
odd+=s[i];
}
for (int i=1; i<32; i+=2)
{
even+=s[i];
}
if(odd==even){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
}
return 0;
}
能請教一下位甚麼嗎?
#include
#include
using namespace std;
int main() {
int n = 0;
while (cin>>n){
bitset s(n);
if(n==0){
cout<<"NO"<<endl;
continue;
}
int odd=0;
int even=0;
for (int i=0; i<32; i+=2)
{
odd+=s[i];
}
for (int i=1; i<32; i+=2)
{
even+=s[i];
}
if(odd==even){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
}
return 0;
}
能請教一下位甚麼嗎?
0是任意數的倍數