poj 1023 The Fun Number System

链接:http://poj.org/problem?id=1023

View Code
 1 #include <cstdio>
 2 #include <cstdlib>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 using namespace std;
 7 typedef long long LL;
 8 int T, N;
 9 LL M;
10 char s[100];
11 int t[100];
12 int main( )
13 {
14     scanf( "%d", &T );
15     while( T -- ){
16         scanf( "%d%s%lld", &N, s, &M );    
17         for(int i=N-1; i>=0; --i){
18             if( (M&1)!=0 )  t[i]=1;    
19             else t[i]=0;    
20             if( s[i]=='p' ) M-=t[i];
21             else M+=t[i];
22             M>>=1;
23         }
24         if( M!=0 )puts( "Impossible" );
25         else {
26             for( int i=0; i<N; ++ i )printf( "%d", t[i] );
27             puts( "" );
28         }    
29     }
30     return 0;
31 }

 

 

 

posted @ 2012-08-11 09:33  淡墨æ末央  阅读(169)  评论(0编辑  收藏  举报