3 条题解
-
1
朱屹宸@苏高实初 (zhuyichen) LV 9 @ 2 年前
#include <iostream>
using namespace std;
bool two[32];//32位int pow(int a,int b){
int ans=1;
for(int i=1;i<=b;i++)
ans*=a;
return ans;
}void TentoTwo(unsigned int n){
for(int i=31;i>=0;i--)
if(n>=pow(2,i)){
// cout<<i<<" ";
two[i]=1;
n-=pow(2,i);
}
// cout<<endl;
}void swap(bool two[]){
for(int i=0;i<=15;i++){//two[i] two[i+16]
bool tmp=two[i];
two[i]=two[i+16];
two[i+16]=tmp;
}
}unsigned int TwotoTen(bool two[]){
unsigned int ans=0;
for(int i=0;i<=31;i++){
if(two[i]==1){
// cout<<i<<" ";
ans+=pow(2,i);
}
}
// cout<<endl;
return ans;
}int main(){
unsigned int n;
cin>>n;
TentoTwo(n);
swap(two);
cout<<TwotoTen(two)<<endl;
return 0;
} -
05 年前@
//位运算快速编码,注意要定义long int型
-
-15 年前@
- 1