数论-北大-1023

0 views
Skip to first unread message

china_sjc

unread,
Aug 6, 2008, 5:35:06 AM8/6/08
to 中国矿业大学徐海学院算法课程
源代码:
#include<iostream.h>
int main()
{
__int64 n;
char np[64];
int i,j,pos,k,casen,sign,num[64];
cin>>casen;
for(i=0;i<casen;i++)
{
cin>>k;cin>>np;cin>>n;pos=0;
if(n>0)sign=1;else sign=-1;
for(j=k-1;j>=0;j--)
{
num[pos]=sign*(n%2);
if(np[j]=='p')n=(n-num[pos])/2;
else n=(n+num[pos])/2;
pos++;
}
if(n)cout<<"Impossible"<<endl;
else
{for(j=k-1;j>=0;j--)cout<<num[j];cout<<endl;}
}
return 0;
}
Reply all
Reply to author
Forward
0 new messages