POJ 3748 (hexadecimal read % x of C ++)

Source: Internet
Author: User

Only a few lines of C ++ programs written by P party ......
First, the bit operation of P has a limit of 2 ^ 30. At this time, even int64 will also be killed by the completion code.

When the value of 2 shl 31 is 1, int64 is a negative number. Therefore, the number of extra bits in shr cannot be increased.
The C-party reading method % x indicates binary
[C ++]
# 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's 30 practices:

[Delphi]
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.

 

Appendix:
Function | example | bitwise operation
---------------------- + --------------------------- + --------------------
Remove the last digit | (101101-> 10110) | x shr 1
Add 0 | (101101-> 1011010) | x shl 1
Add 1 | (101101-> 1011011) | x shl 1 + 1
Change the last digit to 1 | (101100-> 101101) | x or 1
Convert the last bit to 0 | (101101-> 101100) | x or 1-1
Last bitwise | (101101-> 101100) | x xor 1
Change right k to 1 | (101001-> 101101, k = 3) | x or (1 shl (k-1 ))
Change right k to 0 | (101101-> 101001, k = 3) | x and not (1 shl (k-1 ))
Right k-bit inverse | (101001-> 101101, k = 3) | x xor (1 shl (k-1 ))
Last three digits | (1101101-> 101) | x and 7
Last k bit | (1101101-> 1101, k = 5) | x and (1 shl k-1)
Right k bit | (1101101-> 1, k = 4) | x shr (k-1) and 1
Turn the last k bit into 1 | (101001-> 101111, k = 4) | x or (1 shl k-1)
Last k bit inversion | (101001-> 100110, k = 4) | x xor (1 shl k-1)
Change 1 on the right to 0 | (100101111-> 100100000) | x and (x + 1)
Change the first 0 from the right to 1 | (100101111-> 100111111) | x or (x + 1)
Change the continuous 0 on the right to 1 | (11011000-> 11011111) | x or (x-1)
1 in a row on the right | (100101111-> 1111) | (x xor (x + 1) shr 1
Remove the left of the first 1 from the right | (100101000-> 1000) | x and (x xor (x-1 ))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.