| ||||||||||
| 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 | |||||||||
不知哪里就RE了~大家帮帮忙~#include<stdio.h>
panduan(int max,int x[]) /*判断被除数是否是000001的形式*/
{
int result,t;
for(t=2;t<max;t++)
if(x[t]!=0)
{
result=0;
return result;
}
if(x[max]==1)
{
result=1;
return result;
}
else
{
result=0;
return result;
}
}
chufa(int max,int x[]) /*对原数除二*/
{
int t;
for(t=2;t<max;t++)
{
x[t+1]+=x[t]%2*10;
x[t]=x[t]/2;
}
x[max]=x[max]/2;
}
main()
{
int cishu,shuwei,a[70]={0},x[70];
int t,max,panduan(int max,int x[]),chufa(int max,int x[]);
char b[70],temp;
scanf("%d",&cishu);
for(;cishu>0;cishu--)
{
scanf("%d\n",&shuwei);
shuwei++;
for(t=2;t<=shuwei+1;t++)
scanf("%1c",&b[t]);
t=2;
while(1)
{
scanf("%1c",&temp);
if(temp=='\n')
break;
x[t]=temp-48;
t++;
}
max=t-1;
if(max==2&&x[2]==0) /*单独处理n=0的情况*/
{
for(t=2;t<=shuwei;t++)
printf("0");
printf("\n");
continue;
}
if(x[2]<0) /*将负数变正*/
{
for(t=2;t<max;t++)
x[t]=x[t+1];
max--;
for(t=2;t<=shuwei;t++)
{
if(b[t]=='p')
b[t]='n';
else
b[t]='p';
}
}
for(t=shuwei;t>1;t--)
{
if(panduan(max,x))
{
a[t]=1;
break;
}
a[t]=x[max]%2;
if(b[t]=='p'&&a[t]==1)
{
x[max]--;
if(x[max]<0)
{
x[max]+=10;
x[max-1]--;
}
chufa(max,x);
}
if(b[t]=='n'&&a[t]==1)
{
x[max]++;
if(x[max]>9)
{
x[max]-=10;
x[max-1]++;
}
chufa(max,x);
}
if(a[t]==0)
chufa(max,x);
}
if((panduan(max,x)==1&&b[t]=='p'))
{
for(t=2;t<=shuwei;t++)
printf("%d",a[t]);
printf("\n");
}
else
printf("Impossible\n");
for(t=2;t<=shuwei;t++)
{
a[t]=0;
b[t]=0;
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator