P党写几小时的程序 C++才几行……
首先P的位运算有上限2^30 此时 即便是 int64也会因为补码坑死人的
到1 shl 31时 int64 是负数 故 这个时候 不能shr 为多出好多位
造成以上结果的真正原因是 shl 和 shr 只支持到1 shl 30 (Longint)所以在int64或qword会出错 要自己写
C党读入方法 %x 表示 二进制
#include<cstdio> using namespace std; int r,x,y; int main() { scanf("%x,%d,%d",&r,&x,&y); r=r&(~(1<<x)); r=r&(~(1<<y-2)); r=r|(1<<(y-1))|(1<<(y)); printf("%x\n",r); }
P党取到30的做法:
Program P3748; const // ordA=65; orda=97; ord0=48; var s:string; r:qword; x,y:longint; function turn2(c:char):longint; begin if ord(c)>=orda then begin exit(ord(c)-orda+10); end else exit(ord(c)-ord0); end; function turn16(x:qword):longint; begin if (x<>0) then begin turn16:=x and 15; x:=x shr 4; turn16(x); if turn16<=10 then write(turn16) else write(chr(turn16-10+orda)); end; end; function cin:longint; var i:longint; s1:string; begin i:=1; while s[i]<>',' do inc(i); s1:=copy(s,1,i-1); val(s1,cin); delete(s,1,i); end; function cin16:qword; var i,j:longint; s1:string; begin i:=1; while s[i]<>',' do inc(i); s1:=copy(s,1,i-1); cin16:=0; for j:=1 to i-1 do cin16:=cin16 shl 4+turn2(s1[j]); delete(s,1,i); end; begin readln(s); r:=cin16;x:=cin;val(s,y); r:=r and (not (1 shl x)); r:=r and (not (1 shl (y-2))); r:=r or (1 shl (y-1)); r:=r or (1 shl y); turn16(r); writeln; end.更正AC版:
Program P3748; const // ordA=65; orda=97; ord0=48; var s:string; r,k:qword; x,y,i:longint; function turn2(c:char):longint; begin if ord(c)>=orda then begin exit(ord(c)-orda+10); end else exit(ord(c)-ord0); end; function turn16(x:qword):longint; begin if (x<>0) then begin turn16:=x and 15; x:=x div 16; turn16(x); if turn16<=10 then write(turn16) else write(chr(turn16-10+orda)); end; end; function cin:longint; var i:longint; s1:string; begin i:=1; while s[i]<>',' do inc(i); s1:=copy(s,1,i-1); val(s1,cin); delete(s,1,i); end; function cin16:qword; var i,j:longint; s1:string; begin i:=1; while s[i]<>',' do inc(i); s1:=copy(s,1,i-1); cin16:=0; for j:=1 to i-1 do cin16:=cin16 shl 4+turn2(s1[j]); delete(s,1,i); end; function shl2(x:longint):qword; var i:longint; begin shl2:=1; for i:=1 to x do shl2:=shl2*2; end; begin readln(s); r:=cin16;x:=cin;val(s,y); r:=r and (not (shl2(x))); r:=r and (not (shl2(y-2))); r:=r or (shl2(y-1)); r:=r or (shl2(y)); turn16(r); writeln; end.