題目鏈接:http://poj.org/problem?id=3748
解題思路:一開始想到是的模擬,字符串到二進制再到十六進制,然後直接GG。看了TT的代碼之後發現了新的黑科技,%x直接傳入的就是整數的十六進制形式,最後左移右移一下再用%x輸出就行了。
代碼如下:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 0x3f3f3f3f;
const int maxn = 2e4 + 15;
int r, x, y;
void clrbit(int &x, int offset){
x &= ~(1 << offset);
return;
}
void setbit(int &x, int offset){
x |= (1 << offset);
x |= (1 << offset - 1);
clrbit(x, offset - 2);
return;
}
int main(){
scanf("%x,%d,%d", &r, &x, &y);
setbit(r, y);
clrbit(r, x);
printf("%x\n", r);
return 0;
}