Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7737 | Accepted: 3035 |
Description
Input
Output
Sample Input
12345678,0,3
Sample Output
1234567c
Source
方法一: 用系统函数 bitset
#include<iostream>
#include<stdio.h>
#include<bitset>
using namespace std;
int main()
{
int n,x,y;
while(scanf("%x,%d,%d",&n,&x,&y)!=EOF)
{
bitset<32> haha(n);//n为32位的话 最低位为第0位,最高位为第31位
haha.set(x,0);
haha.set(y,1);
haha.set(y-1,1);
haha.set(y-2,0);
printf("%x\n",haha.to_ulong());
}
return 0;
}
直接位操作
#include<stdio.h> int main() { int n,x,y; while(scanf("%x,%d,%d",&n,&x,&y)!=EOF) { int a,b; a=b=1; a=~(a<<x); n=n&a; b=b<<y; n=n|b; b=1; b=b<<y-1; n=n|b; b=1; b=~(b<<y-2); n=n&b; printf("%x\n",n); } return 0; }
另外1种方法 明天贴上