| ||||||||||
| 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 | |||||||||
这里的数据都过了,还是WA,想不明白,有谁给一下测试数据#include <iostream>
#include <string.h>
using namespace std;
int cmp(const void* a,const void* b)
{
return *(char *)b-*(char *)a;
}
int main(int argc, char* argv[])
{
bool sign=0;
char a[1005],div0[1005],div1[1005],div2[1005];
cin>>a;
qsort(a,strlen(a),sizeof(a[0]),cmp);
int count0=0,count5=0,p=0,q=0,r=0;
for(int i=0;i<strlen(a);i++)
{
if(a[i]=='0')
count0++;
if(a[i]=='5')
count5++;
}
if(!count0&&!count5)
cout<<"impossible"<<endl;
else
{
for(i=0;i<strlen(a);i++)
{
if((a[i]-48)%3==0)
div0[r++]=a[i];
if((a[i]-48)%3==1)
div1[p++]=a[i];
if((a[i]-48)%3==2)
{
if(a[i]=='5'&&!sign&&!count0)
{
sign=1;
continue;
}
div2[q++]=a[i];
}
}
if(count0)
{
if(p%3==1&&q%3==0)
p--;
if(p%3==2&&q%3==0)
q--;
if(p%3==2&&q%3==1)
p--;
if(p%3==0&&q%3==1)
q--;
if(p%3==1&&q%3==2)
q--;
if(p%3==0&&q%3==2)
p--;
if(((p==0&&q==0)||q<0||p<0)&&r==count0)
{
cout<<"0"<<endl;
return 0;
}
}
else
{
if(q==0)
{
if(p==0)
{
cout<<"impossible"<<endl;
return 0;
}
if(p%3==2)
p--;
else
{
if(p%3==0)
p-=2;
}
}
else
{
if(p==0)
{
if(q%3==1)
q-=2;
else
{
if(q%3==0)
q-=1;
}
if(q<0)
{
cout<<"impossible"<<endl;
return 0;
}
}
else
{
if(p%3==1&&(q+1)%3==0)
p--;
if(p%3==2&&(q+1)%3==0)
q--;
if(p%3==2&&(q+1)%3==1)
p--;
if(p%3==0&&(q+1)%3==1)
q--;
if(p%3==1&&(q+1)%3==2)
q--;
if(p%3==0&&(q+1)%3==2)
p--;
}
}
}
int p1=0,q1=0,r1=0;
while(p1<p&&q1<q&&r1<r)
{
if(div1[p1]>div2[q1]&&div1[p1]>div0[r1])
cout<<div1[p1++];
else
if(div2[q1]>div0[r1])
cout<<div2[q1++];
else
cout<<div0[r1++];
}
if(p1==p)
{
while(q1<q&&r1<r)
{
if(div2[q1]>div0[r1])
cout<<div2[q1++];
else
cout<<div0[r1++];
}
while(q1<q)
cout<<div2[q1++];
while(r1<r)
cout<<div0[r1++];
}
if(q1==q)
{
while(p1<p&&r1<r)
{
if(div1[p1]>div0[r1])
cout<<div1[p1++];
else
cout<<div0[r1++];
}
while(p1<p)
cout<<div1[p1++];
while(r1<r)
cout<<div0[r1++];
}
if(r1==r)
{
while(p1<p&&q1<q)
{
if(div1[p1]>div2[q1])
cout<<div1[p1++];
else
cout<<div2[q1++];
}
while(p1<p)
cout<<div1[p1++];
while(q1<q)
cout<<div2[q1++];
}
if(sign)
cout<<"5";
cout<<endl;
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator