-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path1023TheFunNumberSystem.cpp
More file actions
53 lines (53 loc) · 1.14 KB
/
1023TheFunNumberSystem.cpp
File metadata and controls
53 lines (53 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<string.h>
#include<stack>
#include<limits.h>
using namespace std;
int main(){
int t,k;
long long n;
char p[70];
int repr[70],cnt;
scanf("%d",&t);
while(t--){
scanf("%d",&k);
scanf("%s",p);
scanf("%lld",&n);
if(n==1LL<<63){
n = -1;
k-=63;
}
//printf("%lld\n",1ll<<63);
if(n<0) {
n = -n;
for(int i=0;i<k;i++) if(p[i]=='p') p[i]='n';
else p[i]='p';
}
cnt = 0;
k--;
bool failed = false;
while(true){
if(k<0) {
break;
}
char c = p[k--];
int d = n%2;
n/=2;
if(c=='p') repr[cnt++] = d;
else{
if(d==1) repr[cnt++] = d, n+=1;
else repr[cnt++] = d;
}
//printf("(%d,%d)\n",d,n);
}
if(n) printf("Impossible\n");
else{
for(int i=cnt-1;i>=0;i--)printf("%d",repr[i]);
printf("\n");
}
}
return 0;
}