首页 > 代码库 > HDU2135 Rolling table【水题】
HDU2135 Rolling table【水题】
Rolling table
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2024 Accepted Submission(s): 977
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
Source
HDU 2007-11 Programming Contest_WarmUp
题目大意:给你一个N*N的字符矩阵,再给一个翻转次数M,翻转一次为90°,M为正
表示顺时针翻转,M为负表示逆时针旋转。
思路:将M对4取余,总共分四种情况,根据翻转情况输出相应结果。
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> using namespace std; char s[12][12]; int main() { int M,N; while(cin >> N >> M) { getchar(); memset(s,0,sizeof(s)); for(int i = 0; i < N; ++i) cin >> s[i]; if(M%4==1 || M%4==-3) { for(int j = 0; j < N; ++j) { for(int i = N-1; i >= 0; --i) cout << s[i][j]; cout << endl; } } else if(M%4 == 2 || M%4==-2) { for(int i = N-1; i >= 0; --i) { for(int j = N-1; j >= 0; --j) cout << s[i][j]; cout << endl; } } else if(M%4 == 3 || M%4==-1) { for(int j = N-1; j >= 0; --j) { for(int i = 0; i < N; ++i) cout << s[i][j]; cout << endl; } } else { for(int i = 0; i < N; ++i) { for(int j = 0; j < N; ++j) cout << s[i][j]; cout << endl; } } } return 0; }
HDU2135 Rolling table【水题】
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。