# 186 条题解

• @ 2017-05-08 12:42:39
``````/*
好水的模拟题OTZ
我们可以直接用位运算来做
于是有了高大上写法
而我这种弱弱只能模拟进制转换来做了
唉我好弱啊
注意这里要用unsigned int而不是int
不然会爆负
*/
/*
高大上写法Orz
#include <iostream>
using namespace std;
unsigned long int n;
int main()
{
cin>>n;
cout<<((n << 16) | (n >> 16))<<endl;
}
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

int a[33];
unsigned int ans;
int k;
int l;

int main()
{
cin>>k;
while(k)
{
a[++l]=k%2;
k/=2;
}
for(int i=1;i<=16;i++)
swap(a[i],a[i+16]);
for(int i=1;i<=32;i++)
ans+=(1<<(i-1))*a[i];
cout<<ans<<endl;
return 0;
}

``````
• @ 2019-01-05 20:08:43

还行c++

``````#include <iostream>

using namespace std ;

unsigned int n , a , b ;

int main()
{
cin >> n ;
a = n / 65536 ;
b = n % 65536 ;
cout << b * 65536 + a ;
return 0 ;
}
``````
• @ 2019-11-11 16:48:53

Orz

• @ 2021-01-08 10:34:20
``````#include <cstdio>
using namespace std;
int main()
{
unsigned int a,b;
scanf("%u",&a);
b=(a<<16)|(a>>16);
printf("%u\n",b);
}
``````
• @ 2018-03-30 10:55:10

不会位操作，只能模拟咯
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
unsigned int n,ans=0;
scanf("%u",&n);
// printf("This is unsigned int n: %u\n",n);
int i,j;
char p[32],q[16];
for(i=0;i<32;i++)
p[i]=0;
for(i=0;i<32;i++)
{
p[i]=n%2;
n=n/2;
//printf("%d",p[i]);
if(n==0) break;
}//printf("\n");
// for(i=0;i<32;i++) printf("%d",p[i]); printf("\n");
for(i=0;i<16;i++)
{
q[i]=p[i];
p[i]=p[i+16];
p[i+16]=q[i];
}
// for(i=0;i<32;i++) printf("%d",p[i]); printf("\n");
for(i=0;i<32;i++)
ans+=pow(2,i)*p[i];
printf("%u",ans);
}

• @ 2016-12-21 17:36:31

楼下有人用这个，强大。一下子忽略了位运算，学习下
```c++
#include <iostream>
using namespace std;
unsigned long int n;
int main(){
cin>>n;
cout<<((n << 16) | (n >> 16))<<endl;
}

• @ 2019-11-11 16:49:49

Orz

• @ 2016-11-17 17:33:03

#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int n,sum=0,m=32;
int a[35]={0};
int main()
{
cin>>n;
while(n>0)
{
if(n<=0)break;
if(n%2==1)
{
a[m]=1;m--;n=(n-1)/2;
}
else
{
m--;n=n/2;
}
}
int c[35]={0};
for(int i=1;i<=16;i++)
{ c[i]=a[i+16];}
for(int i=17;i<=32;i++)
{c[i]=a[i-16];}
for(int i=32;i>0;i--)
{
sum+=c[i]*pow(2,32-i);//乘方函数
}
cout<<sum;
return 0;

}

• @ 2015-08-02 20:52:23

#include <iostream>
#include <stdio.h>
using namespace std;
int num2[33];
int num_2[33];
int main()
{
int n;
scanf("%d",&n);
for(int i=1;;i++)
{
if(n==0)break;
if(n%2==1)
num2[i]=1;
n/=2;
}
for(int i=1;i<=16;i++)
{
num_2[i]=num2[i+16];
num_2[i+16]=num2[i];
}
long long ans=0;
long long n_2=1;
for(int i=1;i<=32;i++)
{
if(num_2[i])ans+=n_2;
n_2*=2;
}
printf("%lld",ans);
}

• @ 2016-12-21 17:32:05

感觉测试数据不强，输入用int就够，条件说输入在2^32内，我试了2^32-1我的程序并不可以啊。建议以后做题遇见2^32输入用long long。
```c++
#include<cstdio>
#include<cmath>
#include<cstring>

int main()
{

int n,i=0;
int q;
int sh[32]= {0};
int ch[32]= {0};
scanf("%d",&n);
//将数字转换为二进制
while(n != 0)
{
sh[i++] = n%2;
n = n/2;
}
//颠倒过来
for(int j=0; j < 32; j++)
{
ch[31-j] = sh[j];
}
//换下位置
for(int j=0; j < 16; j++)
{
q = ch[j];
ch[j] = ch[16+j];
ch[16+j]=q;
}
//输出数字，注意使用long long，因为long不够2^32-1
long long sum = 0;
for(int j=0; j < 32; j++)
{
if(ch[31-j] == 1)
sum += (long long)pow(2,j);//注意使用long long，因为long不够2^32-1
}
printf("%lld\n",sum);

return 0;
}

• @ 2021-01-08 10:35:26
``````unsigned int
``````

就可以

• @ 2016-08-02 11:18:22
``````#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <queue>
#include <bitset>
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)

using namespace std;
typedef long long lg;
#define INF 1<<30

int a;

int main()
{
ios::sync_with_stdio(0);
cin>>a;
bitset<32>x(a),y;
for(int i=0;i<16;i++)
y[i]=x[i+16];
for(int i=16;i<32;i++)
y[i]=x[i-16];
//cout<<x<<endl<<y;
cout<<y.to_ulong();
return 0;
}
``````
• @ 2016-07-30 08:59:24
``````#include <iostream>
using namespace std;

long long N = 0,nFront16 = 0,nLast16 = 0;
int main(){
cin >> N;
//取前16位
nFront16 = N & 4294901760LL;
nFront16 >>= 16;
//取后16位
nLast16 = N & 65535;
//左移16位
nLast16 <<= 16;
//合成新数
nLast16 += nFront16;

cout << nLast16 << endl;
return 0;
}
``````
• @ 2016-06-19 11:45:55

位运算
注意：
1.unsgined long int
2.对此题来说写|和+是一样的，因为其余位都是0

#include <iostream>
using namespace std;
unsigned long int n;
int main(){
cin>>n;
cout<<((n << 16) | (n >> 16))<<endl;
}

• @ 2016-06-19 11:46:35
``````#include <iostream>
using namespace std;
unsigned long int n;
int main(){
cin>>n;
cout<<((n << 16) | (n >> 16))<<endl;
}
``````
• @ 2016-03-20 19:45:58

var n:int64;
begin
writeln((n mod 65536)*65536+n div 65536);
end.

• @ 2016-03-19 12:06:09

太坑了。
#include <iostream>
#include <string>

using namespace std;

int zhuang2_10(string a1)
{
int Ia, Idang, ITemp, Iwei,Ians;
string Sa;
Sa = a1;
Iwei = Sa.size();
Ia = 0;
Ians = 0;
for (ITemp = 0; ITemp < Iwei; ITemp++)
{
Idang = Sa[ITemp] - '0';
Ians = Ians * 2 + Idang;
}
return Ians;
}
string zhuang10_2(int a)
{
int yu,Ia;
string Sa,Syu;
Ia = a;
Sa = "";
while (Ia!= 0)
{
yu = Ia % 2;
Ia = Ia / 2;
Syu = yu + '0';
Sa = Syu+Sa;
}
return(Sa);
}
string bu(string Sa)
{
int Ichang, Temp,Ibu;
string Sb;
Sb = Sa;
Ichang = Sb.size();
if (Ichang >= 32)
return Sb;
else
{
Ibu = 32 - Ichang;
for (Temp = 1; Temp <= Ibu; Temp++)
Sb = '0' + Sb;
return Sb;
}
}
string Swap(string a)
{
string Sa;
char Ca;
int i;
Sa = a;
for (i = 0; i < 16; i++)
{
Ca = Sa[i];
Sa[i] = Sa[16+i];
Sa[16+i] = Ca;
}
return Sa;
}
int main()
{
unsigned a;
string Sa;
cin >> a;
Sa = zhuang10_2(a);
Sa = bu(Sa);
Sa = Swap(Sa);
a = zhuang2_10(Sa);
cout << a;
return 0;
}

• @ 2015-11-03 09:42:37

Program P1201;

Var i:longint;n,sum:int64;
a,b:array[1..33]of longint;
c:array[1..33]of int64;

Begin
while n>0 do begin
a[i]:=n mod 2;
dec(i);
n:=n div 2;
end;
for i:=1 to 16 do b[i]:=a[16+i];
for i:=17 to 32 do b[i]:=a[i-16];
c[32]:=1;
for i:=31 downto 1 do c[i]:=c[i+1]*2;
sum:=0;
for i:=1 to 32 do sum:=c[i]*b[i]+sum;
writeln(sum);
end.

• @ 2015-10-25 21:08:48

很简单的一道题目，就是个二进制运算，注意是unsigned int不是int就好了
测试数据 #0: Accepted, time = 0 ms, mem = 524 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 524 KiB, score = 10
测试数据 #2: Accepted, time = 15 ms, mem = 528 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 520 KiB, score = 10
测试数据 #4: Accepted, time = 15 ms, mem = 520 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 524 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 520 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 524 KiB, score = 10
测试数据 #8: Accepted, time = 1 ms, mem = 520 KiB, score = 10
测试数据 #9: Accepted, time = 15 ms, mem = 520 KiB, score = 10
Accepted, time = 46 ms, mem = 528 KiB, score = 100
代码
#include <iostream>
using namespace std;
int main()
{
unsigned int x;
cin>>x;
cout<<(unsigned int)(((x<<16)&0xFFFF0000)|((x>>16)&0x0000FFFF))<<endl;
return 0;
}

• @ 2015-10-18 15:49:29

测试数据 #0: Accepted, time = 1 ms, mem = 520 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 524 KiB, score = 10
测试数据 #2: Accepted, time = 15 ms, mem = 524 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 520 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 524 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 524 KiB, score = 10
测试数据 #6: Accepted, time = 1 ms, mem = 524 KiB, score = 10
测试数据 #7: Accepted, time = 15 ms, mem = 524 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 524 KiB, score = 10
测试数据 #9: Accepted, time = 1 ms, mem = 524 KiB, score = 10
Accepted, time = 33 ms, mem = 524 KiB, score = 100

• @ 2015-10-13 00:08:45

var m,n:int64;
begin
m:=1 shl 16;
n:=(n mod m)shl 16+n shr 16;
writeln(n);
end.
{________________________________________}
var s:longword;
begin
write(swap(s));
end.

• @ 2015-08-13 22:00:15

var
s:longword;
begin
writeln(swap(s));
end.

• @ 2015-08-03 16:43:15

非本人所写，作
program e1201;
var n,m,k,l,x,y:int64;
i,j:longint;
a,b,c,f:array[0..100]of int64;
begin
k:=0;
for i:=1 to 16 do
begin
a[i]:=n and 1;
n:=n shr 1;
end;
for i:=1 to 16 do
begin
b[i]:=n and 1;
n:=n shr 1;
end;
for i:=16 downto 1 do
begin
inc(k);
c[k]:=a[i];
end;
for i:=16 downto 1 do
begin
inc(k);
c[k]:=b[i];
end;
for i:=1 to k do
if c[i]=1 then begin
inc(l);
f[l]:=32-i;
end;
for i:=1 to l do
begin
y:=1;
for j:=1 to f[i] do
y:=y*2;
x:=x+y;
end;
writeln(x);
end.

• @ 2015-08-03 16:42:31

program e1201;
var n,m,k,l,x,y:int64;
i,j:longint;
a,b,c,f:array[0..100]of int64;
begin
k:=0;
for i:=1 to 16 do
begin
a[i]:=n and 1;
n:=n shr 1;
end;
for i:=1 to 16 do
begin
b[i]:=n and 1;
n:=n shr 1;
end;
for i:=16 downto 1 do
begin
inc(k);
c[k]:=a[i];
end;
for i:=16 downto 1 do
begin
inc(k);
c[k]:=b[i];
end;
for i:=1 to k do
if c[i]=1 then begin
inc(l);
f[l]:=32-i;
end;
for i:=1 to l do
begin
y:=1;
for j:=1 to f[i] do
y:=y*2;
x:=x+y;
end;
writeln(x);
end.

ID
1201

3

(无)

3686

1811

49%

6