【题目描述】
C++ 中 int 型整数内码是一个 32 位的 0101 序列,该 0101 序列有些是对称的,有些是不对称的。
对于给定的一个整数,在一些场合,需要判断其整数内码的对称性。
【输入】
输入中含有一个整数 nn 。
【输出】
如果 nn内码对称,输出"YES
",否则输出"NO
"。
【输入样例】
2147483646
【输出样例】
YES
源代码:
#include<bits/stdc++.h> using namespace std; int main() { int n,ans[1000+10],num=0; cin>>n; bitset<32> a(n); for(int i=0,j=31;i<j;i++,j--) { if( a[i]!=a[j] ) { cout<<"NO"<<endl; return 0; } } cout<<"YES"<<endl; return 0; }