hdu2135

Problem Description
After the 32nd ACM/ICPC regional contest, Wiskey is beginning to prepare for CET-6. He has an English words table and read it every morning.
One day, Wiskey's chum wants to play a joke on him. He rolling the table, and tell Wiskey how many time he rotated. Rotate 90 degrees clockwise or count-clockwise each time.
The table has n*n grids. Your task is tell Wiskey the final status of the table.

Input
Each line will contain two number.
The first is postive integer n (0 < n <= 10).
The seconed is signed 32-bit integer m.
if m is postive, it represent rotate clockwise m times, else it represent rotate count-clockwise -m times.
Following n lines. Every line contain n characters.

Output
Output the n*n grids of the final status.

思路:你把这个矩阵写在纸上,然后转个90度,180度,270度,360度就可以发现一个规律。

那就是m=m%4;   

1.当m=0的时候,

2当m==1||m==-3的时候

3当m==2||m==-2的时候

4.当m==3||m==-1的时候

然后就可以做了。

我在做的时候定义的数组为INT,然后输出的时候什么都数不出来,然后发现自己弄得居然是int,要改成char.

#include<stdio.h>
int main(){
int n,m;
while(scanf("%d %d",&n,&m)!=EOF){
    int i,j;
    char f[101][101];
    for(i=1;i<=n;i++){
            getchar();
            for(j=1;j<=n;j++){
        scanf("%c",&f[i][j]);}

    }
    m=m%4;
    if(m==0){
        for(i=1;i<=n;i++){
            for(j=1;j<=n;j++){
                printf("%c",f[i][j]);
            }
            printf("\n");
        }
    }
    if(m==1||m==-3){
        for(j=1;j<=n;j++){
        for(i=n;i>=1;i--){
            printf("%c",f[i][j]);
            }
            printf("\n");
        }
    }
    if(m==2||m==-2){
        for(i=n;i>=1;i--){
            for(j=n;j>=1;j--){
                printf("%c",f[i][j]);
            }
            printf("\n");
        }

    }
    if(m==3||m==-1){
        for(j=n;j>=1;j--){
            for(i=1;i<=n;i++){
                printf("%c",f[i][j]);
            }
            printf("\n");
        }
    }

}
return 0;
}


猜你喜欢

转载自blog.csdn.net/xdyzengqian/article/details/79981637