【字符串】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;
}
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;
}
相关文章推荐
- SSH登录异常(someone is doing something nasty)
- FastJson--阿里巴巴公司开源的速度最快的Json和对象转换工具
- 程序员与生俱来的好奇心
- SVN中Branch的创建与合并
- 粒子的控制
- 线程间通信
- RecyclerView,CardView导入AndroidStudio
- 最长回文子串 hihocode 1032
- 微信扫描二维码-电脑上网
- MySQL数据库引擎介绍、区别、创建和性能测试的深入分析
- iOS 日历
- TortoiseSVN 同步分支
- [android] 手机卫士来电显示号码归属地
- Android Studio 解决aapt "finished with non-zero exit value 1"问题,aaptnon-zero
- idea更改新建文件模板和注释
- 快速排序
- 银行家算法
- 转自:Java通过SMS短信平台实现发短信功能
- 9个使用OpenCV进行手势检测和识别的教程
- C++实验5