标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 8856 | Accepted: 3535 |
Description
Input
Output
Sample Input
12345678,0,3
Sample Output
1234567c
Source
做法一:
http://happyboy200032.blog.163.com/blog/static/46903113201291252033712/
1 #include<cstdio> 2 #include<cmath> 3 #include<cstring> 4 #include<iostream> 5 #include<bitset>//二进制类,bit位,初始为0 6 using namespace std; 7 int main(){ 8 int r,x,y; 9 while(scanf("%x,%d,%d",&r,&x,&y)==3){//输入16进制数 10 bitset<32> b(r); 11 b.reset(x); 12 b.set(y); 13 b.set(y-1); 14 b.reset(y-2); 15 printf("%x\n",b.to_ulong());//将二进制转换为unsign long数值 16 } 17 return 0; 18 }
做法二:
模拟
1 #include<cstdio> 2 #include<cmath> 3 #include<cstring> 4 #include<iostream> 5 #include<bitset> 6 using namespace std; 7 int bit[32]; 8 int main(){ 9 int r,x,y; 10 while(scanf("%x,%d,%d",&r,&x,&y)==3){ 11 memset(bit,false,sizeof(bit)); 12 int i=0; 13 for(;i<32;i++){ 14 bit[i]=r&1; 15 r=r>>1; 16 } 17 bit[x]=0; 18 bit[y]=1; 19 bit[y-1]=1; 20 bit[y-2]=0; 21 for(i=31;i>=0;i--){ 22 r=r<<1; 23 r=r|bit[i]; 24 } 25 printf("%x\n",r); 26 } 27 return 0; 28 }
标签:
原文地址:http://www.cnblogs.com/Deribs4/p/4299132.html