#include <stdio.h>
void action_1 ( int s[][ 100 ] , int *a , int *b ) // 順時針旋轉
{
int s1_cpy[ 100 ][ 100 ] , i , j ;
int A ;
for ( i = 0 ; i < *b ; i ++ ){
A = *a - 1 ;
for ( j = 0 ; j < *a ; j ++ ){
s1_cpy[ i ][ j ] = s[ A ][ i ] ;
A-- ;
}
}
for ( i = 0 ; i < *b ; i ++ )
for ( j = 0 ; j < *a ; j ++ )
s[ i ][ j ] = s1_cpy[ i ][ j ] ;
int temp = *a ; *a = *b ; *b = temp ;
}
void action_2 ( int s[][ 100 ] , int a , int b ) // 上下翻轉
{
int s2_cpy[ 100 ][ 100 ] , i , j , A = a - 1 ;
for ( i = 0 ; i < a ; i ++ ){
for ( j = 0 ; j < b ; j ++ )
s2_cpy[ i ][ j ] = s[ A ][ j ] ;
A-- ;
}
for ( i = 0 ; i < a ; i ++ )
for ( j = 0 ; j < b ; j ++ )
s[ i ][ j ] = s2_cpy[ i ][ j ] ;
}
int main()
{
int a , b , i , j ;
while ( scanf ( "%d %d" , &a , &b ) != EOF ){
int s[ 100 ][ 100 ] = {} ;
for ( i = 0 ; i < a ; i ++ )
for ( j = 0 ; j < b ; j ++ )
scanf ( " %d" , &s[ i ][ j ] ) ;
action_2 ( s , a , b ) ; // 注意 一定是先翻轉再旋轉
action_1 ( s , &a , &b ) ;
for ( i = 0 ; i < a ; i ++ ){
for ( j = 0 ; j < b - 1 ; j ++ )
printf ( "%d " , s[ i ][ j ] ) ;
printf ( "%d\n" , s[ i ][ b - 1 ] ) ;
}
}
return 0 ;
}
執行結果:
AC 0ms 128kb