HDOJ(HDU) 2135 Rolling table
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
(注意是字符啊!字符!我开始以为是n*n个1-n*n的数字。。。WA了几次)
输入n*n个字符,每次旋转以90°为单位,m>0表示顺时针旋转
m<0逆时针旋转。
矩阵旋转后存在四种状态。所以将m取余4,然后判断是哪种状态,然后旋转即可。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
int m = sc.nextInt();
String strs[]=new String[n];
for(int i=0;i<n;i++){
strs[i]=sc.next();
}
if(m%4==0){
for(int i=0;i<n;i++){
System.out.println(strs[i]);
}
continue;
}
if(m>0){
m=m%4;
if(m==1){
for(int i=0;i<n;i++){
for(int j=n-1;j>=0;j--){
System.out.print(strs[j].charAt(i));
}
System.out.println();
}
continue;
}
if(m==2){
for(int i=n-1;i>=0;i--){
for(int j=n-1;j>=0;j--){
System.out.print(strs[i].charAt(j));
}
System.out.println();
}
continue;
}
if(m==3){
for(int i=n-1;i>=0;i--){
for(int j=0;j<n;j++){
System.out.print(strs[j].charAt(i));
}
System.out.println();
}
continue;
}
}
if(m<0){
m=m*(-1);
m=m%4;
if(m==3){
for(int i=0;i<n;i++){
for(int j=n-1;j>=0;j--){
System.out.print(strs[j].charAt(i));
}
System.out.println();
}
continue;
}
if(m==2){
for(int i=n-1;i>=0;i--){
for(int j=n-1;j>=0;j--){
System.out.print(strs[i].charAt(j));
}
System.out.println();
}
continue;
}
if(m==1){
for(int i=n-1;i>=0;i--){
for(int j=0;j<n;j++){
System.out.print(strs[j].charAt(i));
}
System.out.println();
}
}
}
}
}
}
HDOJ(HDU) 2135 Rolling table的更多相关文章
- HDU 2135 Rolling table
http://acm.hdu.edu.cn/showproblem.php?pid=2135 Problem Description After the 32nd ACM/ICPC regional ...
- HDOJ(HDU).1412 {A} + {B} (STL SET)
HDOJ(HDU).1412 {A} + {B} (STL SET) 点我挑战题目 题意分析 大水题,会了set直接用set即可. 利用的是set的互异性(同一元素有且仅有一项). #include ...
- HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)
HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...
- HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)
HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i ...
- HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)
HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...
- HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)
HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那 ...
- HDOJ(HDU).2191. 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 (DP 多重背包+二进制优化)
HDOJ(HDU).2191. 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 (DP 多重背包+二进制优化) 题意分析 首先C表示测试数据的组数,然后给出经费的金额和大米的种类.接着是每袋大米的 ...
- HDOJ(HDU).2159 FATE (DP 带个数限制的完全背包)
HDOJ(HDU).2159 FATE (DP 带个数限制的完全背包) 题意分析 与普通的完全背包大同小异,区别就在于多了一个个数限制,那么在普通的完全背包的基础上,增加一维,表示个数.同时for循环 ...
- HDOJ(HDU).4508 湫湫系列故事――减肥记I (DP 完全背包)
HDOJ(HDU).4508 湫湫系列故事――减肥记I (DP 完全背包) 题意分析 裸完全背包 代码总览 #include <iostream> #include <cstdio& ...
随机推荐
- R cannot be resolved to a variable
1. 检查Android 的SDK是否丢失需要重新下载,检查build path,把需要导入的JAR包确认都导入成功 2. 确保class没有import Android.R,注意是不能有Androi ...
- android 简单的开机自启
今天我们主要来探讨android怎么让一个service开机自动启动功能的实现.Android手机在启动的过程中会触发一个Standard Broadcast Action,名字叫android.in ...
- Creating a web application.
About creating web GIS applications As you learn and use ArcGIS for Server, you'll probably reach th ...
- (转载)Javascript 进阶 作用域 作用域链
载请标明出处:http://blog.csdn.net/lmj623565791/article/details/25076713 一直觉得Js很强大,由于长期不写js代码,最近刚好温故温故. 1.J ...
- 在万网虚拟主机上部署MVC5
参考 要想部署mvc,需要把一些mvc用到的全局程序集改为本地部署,通过N次试验,终于搞定. 特写个备忘录,免得以后忘了. 首先更改web.config,在里面加上 <system.web> ...
- wpf 窗体中显示当前系统时间
先看一下效果: 这其实是我放置了两个TextBlock,上面显示当前的日期,下面显示时间. 接下来展示一下代码: 在XAML中: <StackPanel Width="205" ...
- hdoj 2040
#include<stdio.h>int i,j,s1,s2;int cha(int a,int b){ s1=0; s2=0; for(i=1;i<a;i++) { ...
- SGU 190.Dominoes(二分图匹配)
时间限制:0.25s 空间限制:4M 题意: 给定一个N*N的棋盘,一些格子被移除,在棋盘上放置一些1*2的骨牌,判定能否放满,并且输出任意方案. Solution: 首先考虑对棋盘的一个格子黑白染色 ...
- mongo db安装和php,python插件安装
安装mongodb 1.下载,解压mongodb(下载解压目录为/opt) 在/opt目录下执行命令 wget fastdl.mongodb.org/linux/mongodb-linux-x86_6 ...
- 关于Weblogic 10.3.1集群及调优经历
一. 集群 ·集群易于管理.灵活的负载平衡.较强的安全机制 ·配置前的规划 操作系统 硬件配置 角色 windows IP: 192.168.1.101:7001 AdminServer windo ...