挺有意思的题目,不过还是很水 以下代码C++能过,G++不能 #include <cstdio> #include <cstring> #include <cstdlib> using namespace std; const int MAX = 3010; char result[MAX][MAX]; int row,col; char input[10][10]; int mypow( int original , int time ) { int result = 1; for( int i = 0 ; i != time ; ++i ) result *= original; return result; } void go( int curx , int cury , int times ) { if( times == 1 ) { for( int i = 0 ; i != row ; ++i ) { for( int j = 0 ; j != col ; ++j ) result[ curx + i ][ cury + j ] = input[i][j]; } } else { int k1 = mypow( row , times - 1 ); int k2 = mypow( col , times - 1 ); for( int i = 0 ; i != row ; ++i ) for( int j = 0 ; j != col ; ++j ) if( input[i][j] != ' ' ) { go( curx + k1 * i , cury + k2 * j , times - 1 ); } } } int main() { char buffer[1024]; int maxrow,maxcol; while( gets(buffer) , row = col = atoi( buffer ) , row != 0 ) { for( int i = 0 ; i != row ; ++i ) gets( input[i]); int times; gets( buffer ); times = atoi( buffer ); maxrow = mypow( row , times ); maxcol = mypow( col , times ); for( int i = 0 ; i != maxrow ; ++i ) { for( int j = 0 ; j != maxcol ; ++j ) result[i][j] = ' '; result[i][maxcol] = '/0'; } go( 0 , 0 , times ); for( int i = 0 ; i != maxrow ; ++i ) printf("%s/n",result[i]); } return 0; }