【字符串】HDU2135Rolling table

来源:互联网 发布:java五个框架有哪些 编辑:程序博客网 时间:2024/05/06 02:45

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2135

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.
 

Sample Input
3 21234567893 -1123456789
 

Sample Output
987654321369258147
 

Author
Wiskey
 


代码:

#include<iostream>#include<cstring>using namespace std;int main(){    char a[15][15];    int n,m;    cin.sync_with_stdio(false);    while(cin>>n>>m){        for(int i=1;i<=n;i++)            for(int j=1;j<=n;j++)                cin>>a[i][j];        while(m<0) m+=4;        m%=4;        if(m==1){            for(int j=1;j<=n;j++){                for(int i=n;i>0;i--){                    cout<<a[i][j];                    if(i==1) cout<<endl;                }            }        }else if(m==2){            for(int i=n;i>0;i--){                for(int j=n;j>0;j--){                    cout<<a[i][j];                    if(j==1)cout<<endl;                }            }        }else if(m==3){            for(int j=n;j>0;j--){                for(int i=1;i<=n;i++){                    cout<<a[i][j];                    if(i==n) cout<<endl;                }            }        }else if(m==0){            for(int i=1;i<=n;i++)                for(int j=1;j<=n;j++){                    cout<<a[i][j];                    if(j==n)cout<<endl;                }        }    }    return 0;}


0 0