蓝桥杯JAVA-32.二维数组(矩阵)实现旋转模板(JAVA实现)
生活随笔
收集整理的這篇文章主要介紹了
蓝桥杯JAVA-32.二维数组(矩阵)实现旋转模板(JAVA实现)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
個人博客
www.tothefor.com
藍橋杯復習知識點匯總
目錄
順時針旋轉
90°
import java.io.*; import java.math.BigInteger; import java.util.*;/*** @Author DragonOne* @Date 2021/12/5 21:27* @墨水記憶 www.tothefor.com*/ public class Main {public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));public static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));public static StreamTokenizer cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));public static PrintWriter cout = new PrintWriter(new OutputStreamWriter(System.out));public static Scanner sc = new Scanner(System.in);public static int monthes[]= {0,31,28,31,30,31,30,31,31,30,31,30,31};//一年中的12個月每月的天數public static int maxd = 1000+7;public static int INF = 0x3f3f3f3f;public static int mod = 998244353;public static int[][] a = new int[maxd][maxd];public static int[][] b = new int[maxd][maxd];public static void main(String[] args) throws Exception {int n = nextInt(); //行int m = nextInt(); //列for(int i=0;i<n;++i){for(int j=0;j<m;++j){a[i][j]=nextInt();}}//旋轉后為m行n列for(int i=0;i<m;++i){ //行for(int j=0;j<n;++j){ //列b[i][j]=a[n-1-j][i];}}for(int i=0;i<m;++i){for(int j=0;j<n;++j){System.out.print(b[i][j]+" ");}System.out.println();}closeAll();}public static int gcd(int a,int b){ // 不需要判斷a和b的大小while(b>0){a%=b;b^=a;a^=b;b^=a; // while(b^=a^=b^=a%=b);}return a; // return (a % b == 0) ? b : gcd(b, a%b);}public static void cinInit(){cin.wordChars('a', 'z');cin.wordChars('A', 'Z');cin.wordChars(128 + 32, 255);cin.whitespaceChars(0, ' ');cin.commentChar('/');cin.quoteChar('"');cin.quoteChar('\'');cin.parseNumbers(); //可單獨使用還原數字}public static int nextInt() throws Exception {cin.nextToken();return (int) cin.nval;}public static long nextLong() throws Exception {cin.nextToken();return (long) cin.nval;}public static double nextDouble() throws Exception {cin.nextToken();return cin.nval;}public static String nextString() throws Exception {cin.nextToken();return cin.sval;}public static void closeAll() throws Exception {cout.close();in.close();out.close();} }180°
import java.io.*; import java.math.BigInteger; import java.util.*;/*** @Author DragonOne* @Date 2021/12/5 21:27* @墨水記憶 www.tothefor.com*/ public class Main {public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));public static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));public static StreamTokenizer cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));public static PrintWriter cout = new PrintWriter(new OutputStreamWriter(System.out));public static Scanner sc = new Scanner(System.in);public static int monthes[]= {0,31,28,31,30,31,30,31,31,30,31,30,31};//一年中的12個月每月的天數public static int maxd = 1000+7;public static int INF = 0x3f3f3f3f;public static int mod = 998244353;public static int[][] a = new int[maxd][maxd];public static int[][] b = new int[maxd][maxd];public static void main(String[] args) throws Exception {int n = nextInt(); //行int m = nextInt(); //列for(int i=0;i<n;++i){for(int j=0;j<m;++j){a[i][j]=nextInt();}}//旋轉后還是為 n行 m列for(int i=0;i<n;++i){ //行for(int j=0;j<m;++j){ //列b[i][j]=a[n-1-i][m-1-j];}}for(int i=0;i<n;++i){for(int j=0;j<m;++j){System.out.print(b[i][j]+" ");}System.out.println();}closeAll();}public static int gcd(int a,int b){ // 不需要判斷a和b的大小while(b>0){a%=b;b^=a;a^=b;b^=a; // while(b^=a^=b^=a%=b);}return a; // return (a % b == 0) ? b : gcd(b, a%b);}public static void cinInit(){cin.wordChars('a', 'z');cin.wordChars('A', 'Z');cin.wordChars(128 + 32, 255);cin.whitespaceChars(0, ' ');cin.commentChar('/');cin.quoteChar('"');cin.quoteChar('\'');cin.parseNumbers(); //可單獨使用還原數字}public static int nextInt() throws Exception {cin.nextToken();return (int) cin.nval;}public static long nextLong() throws Exception {cin.nextToken();return (long) cin.nval;}public static double nextDouble() throws Exception {cin.nextToken();return cin.nval;}public static String nextString() throws Exception {cin.nextToken();return cin.sval;}public static void closeAll() throws Exception {cout.close();in.close();out.close();} }270°
import java.io.*; import java.math.BigInteger; import java.util.*;/*** @Author DragonOne* @Date 2021/12/5 21:27* @墨水記憶 www.tothefor.com*/ public class Main {public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));public static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));public static StreamTokenizer cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));public static PrintWriter cout = new PrintWriter(new OutputStreamWriter(System.out));public static Scanner sc = new Scanner(System.in);public static int monthes[]= {0,31,28,31,30,31,30,31,31,30,31,30,31};//一年中的12個月每月的天數public static int maxd = 1000+7;public static int INF = 0x3f3f3f3f;public static int mod = 998244353;public static int[][] a = new int[maxd][maxd];public static int[][] b = new int[maxd][maxd];public static void main(String[] args) throws Exception {int n = nextInt(); //行int m = nextInt(); //列for(int i=0;i<n;++i){for(int j=0;j<m;++j){a[i][j]=nextInt();}}//旋轉后為 m行 n列for(int i=0;i<m;++i){ //行for(int j=0;j<n;++j){ //列b[i][j]=a[j][m-1-i];}}for(int i=0;i<m;++i){for(int j=0;j<n;++j){System.out.print(b[i][j]+" ");}System.out.println();}closeAll();}public static int gcd(int a,int b){ // 不需要判斷a和b的大小while(b>0){a%=b;b^=a;a^=b;b^=a;// while(b^=a^=b^=a%=b);}return a;// return (a % b == 0) ? b : gcd(b, a%b);}public static void cinInit(){cin.wordChars('a', 'z');cin.wordChars('A', 'Z');cin.wordChars(128 + 32, 255);cin.whitespaceChars(0, ' ');cin.commentChar('/');cin.quoteChar('"');cin.quoteChar('\'');cin.parseNumbers(); //可單獨使用還原數字}public static int nextInt() throws Exception {cin.nextToken();return (int) cin.nval;}public static long nextLong() throws Exception {cin.nextToken();return (long) cin.nval;}public static double nextDouble() throws Exception {cin.nextToken();return cin.nval;}public static String nextString() throws Exception {cin.nextToken();return cin.sval;}public static void closeAll() throws Exception {cout.close();in.close();out.close();} }總結
以上是生活随笔為你收集整理的蓝桥杯JAVA-32.二维数组(矩阵)实现旋转模板(JAVA实现)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ANSYS的几种动画模式
- 下一篇: 优秀logo,最基础的设计技巧(一)