WA9
Послано
Andrex 28 окт 2010 18:22
please, help me...
my code:
#include <iostream>
using namespace std;
int main()
{
int n,m[16],k;
char c[48][20],v[16][20],ch[3][20];
cin>>n;
for(int i=0;i<n*3;i++)
cin>>c[i];
for(int i=0;i<n;i++)
{
cin>>k;
m[i]=k;
}
k=(m[0]-1)*3;
if((strcmp(c[k],c[k+1])<=0)&&(strcmp(c[k],c[k+2])<=0)){strcpy(v[0],c[k]);}
if((strcmp(c[k+1],c[k])<=0)&&(strcmp(c[k+1],c[k+2])<=0)){strcpy(v[0],c[k+1]);}
if((strcmp(c[k+1],c[k])<=0)&&(strcmp(c[k+1],c[k+2])<=0)){strcpy(v[0],c[k+1]);}
for(int i=1;i<n;i++)
{
k=(m[i]-1)*3;
if((strcmp(c[k],c[k+1])<=0)&&(strcmp(c[k],c[k+2])<=0))
{
strcpy(ch[0],c[k]);
if(strcmp(c[k+1],c[k+2])<=0)
{
strcpy(ch[1],c[k+1]);
strcpy(ch[2],c[k+2]);
}
else
{
strcpy(ch[2],c[k+1]);
strcpy(ch[1],c[k+2]);
}
}
if((strcmp(c[k+1],c[k])<=0)&&(strcmp(c[k+1],c[k+2])<=0))
{
strcpy(ch[0],c[k+1]);
if(strcmp(c[k],c[k+2])<=0)
{
strcpy(ch[1],c[k]);
strcpy(ch[2],c[k+2]);
}
else
{
strcpy(ch[2],c[k]);
strcpy(ch[1],c[k+2]);
}
}
if((strcmp(c[k+2],c[k])<=0)&&(strcmp(c[k+2],c[k+1])<=0))
{
strcpy(ch[0],c[k+2]);
if(strcmp(c[k],c[k+1])<=0)
{
strcpy(ch[1],c[k]);
strcpy(ch[2],c[k+1]);
}
else
{
strcpy(ch[2],c[k]);
strcpy(ch[1],c[k+1]);
}
}
if(strcmp(v[i-1],ch[0])<=0)
{
strcpy(v[i],ch[0]);
}
else
{
if(strcmp(v[i-1],ch[1])<=0)
{
strcpy(v[i],ch[1]);
}
else
{
if(strcmp(v[i-1],ch[2])<=0)
{
strcpy(v[i],ch[2]);
}
else
{
cout<<"IMPOSSIBLE";
return 0;
}
}
}
}
for(int i=0;i<n;i++)
{
cout<<v[i]<<endl;
}
return 0;
}