当前位置: 代码迷 >> 综合 >> HDOJ 2135 Rolling table
  详细解决方案

HDOJ 2135 Rolling table

热度:46   发布时间:2023-10-21 18:50:29.0

HDACM 2135

逆时针旋转90度等于顺时针旋转270度

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();char grids[][] = new char[n][n];for (int i = 0; i < n; i++) {String str = sc.next();for (int j = 0; j < n; j++) {grids[i][j] = str.charAt(j);}}if (m >= 0) {m = m % 4;} else {m = (m % 4 + 4)%4;}if (m == 0) {for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {System.out.print(grids[i][j]);}System.out.println();}}if (m == 1) {for (int i = 0; i < n; i++) {for (int j = n-1; j >= 0; j--) {System.out.print(grids[j][i]);}System.out.println();}}if (m == 2) {for (int i = n-1; i >= 0; i--) {for (int j = n-1; j >= 0; j--) {System.out.print(grids[i][j]);}System.out.println();}}if (m == 3) {for (int i = n-1; i >= 0; i--) {for (int j = 0; j < n; j++) {System.out.print(grids[j][i]);}System.out.println();}}}sc.close();}
}
  相关解决方案