CSUOJ 1226:ACMグループの内戦

5698 ワード

http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1226
これも月試合問題で、当時どう思っていたのか分からないが、この問題を書いていなかった...2つの文字列の中の文字には対応関係があり、1対多と多
一つもだめだ...
#include<cstdio>
#include<cstring>
#include<cstdlib>
#define SIZE 300

char s1[SIZE], s2[SIZE], s3[SIZE], s4[SIZE], a[SIZE], b[SIZE], c[SIZE], d[SIZE];
bool f1[100], f2[100];

int main()
{
while( scanf( "%s%s%s%s", s1, s2, s3, s4) == 4)
{
memset( f1, false, sizeof f1);
memset( f2, false, sizeof f2);
int len = strlen( s1);
for( int i = 0; i < len; i ++)
{
if( !f1[ s1[i] - 48 ] && !f2[ s2[i] - 48] ) {
a[ s1[i] - 48 ] = s2[i];
f1[ s1[i] - 48 ] = true;
b[ s2[i] - 48 ] = s1[i];
f2[ s2[i] - 48 ] = true;
}
if( f1[ s1[i] - 48 ] && a[ s1[i] - 48 ] != s2[i])
f1[ s1[i] - 48 ] = false;

if( f2[ s2[i] - 48 ] && b[ s2[i] - 48 ] != s1[i])
f2[ s2[i] - 48 ] = false;
}
bool flag = true;
len = strlen(s3);
for( int i = 0; i < len; i ++)
{
if( !f1[ s3[i] - 48 ]) {
flag = false;
break;
}
else
c[i] = a[ s3[i] - 48 ];
}
if( flag)
for( int i = 0; i < len; i ++)
printf( "%c", c[i]);
else
printf( "Wrong");
printf( "
");
flag = true;
len = strlen(s4);
for( int i = 0; i < len; i ++)
{
if( !f2[ s4[i] - 48 ]) {
flag = false;
break;
}
else
d[i] = b[ s4[i] - 48];
}
if( flag)
for( int i = 0; i < len; i ++)
printf( "%c", d[i]);
else
printf( "Wrong");
printf( "
");
}
return 0;
}