poj 3087解题报告

时间:2012-06-26 15:09:32
【文件属性】:

文件名称:poj 3087解题报告

文件大小:1KB

文件格式:CPP

更新时间:2012-06-26 15:09:32

poj 3087解题报告

#include #include #include #include #include using namespace std; #define MAX_N 200+10 map< string , bool >str; char s1[MAX_N],s2[MAX_N],s12[MAX_N],s[MAX_N]; void add( int n ){ int i; int value = 0; for( i = 0 ; i < n ; i++ ){ s[value++] = s2[i]; s[value++] = s1[i]; } s[value] = '\0'; } int main() { freopen( "in.txt" , "r" , stdin ); freopen( "out.txt" , "w" , stdout ); int cas , i , j , t , n; scanf("%d",&cas); for( i = 1 ; i <= cas ; i++ ){ scanf("%d",&n ); cin >> s1 >> s2 >> s12; t = 1; add( n ); bool boo = false; while( str.find( s ) == str.end() ){ if( !strcmp( s , s12 ) ){ printf("%d %d\n",i,t); boo = true; break; } str[ s ] = true; for( j = 0 ; j < n ; j++ ){ s1[j] = s[j]; } s1[n] = '\0'; int a = 0; for( j = n ; j < 2*n ; j++ ){ s2[a++] = s[j]; } s2[a] = '\0'; add( n ); t++; } if( !boo ){ printf("%d -1\n",i); } } return 0; }


网友评论