CSUOJ 1226: ACM小组的内战

http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1226

这也是月赛题,不知道当时怎么想的,居然没有写这道题...两个字符串中的字符有对应的关系,一对多和多

对一都不行...

#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( "\n");
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( "\n");
}
return 0;
}

 

你可能感兴趣的:(ACM)