您的位置:首页 > 其它

【字符串】HDU2135Rolling table

2016-05-07 16:01 351 查看
题目链接: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 2
123
456
789
3 -1
123
456
789

 

Sample Output

987
654
321
369
258
147

 

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: