Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
原来leading zero也要输出唉唉矣 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; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator