java
N x N 행렬이 주어질 때, 시계 방향으로 90도, 180도, 270도 회전한 모양을 출력하는 문제
반복문을 활용해 문제를 풀었다.
어렵지 않게 해결한 문제지만, 비슷한 유형의 문제들을 더 풀어볼 계획이다.
import java.util.Scanner;
import java.io.FileInputStream;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T;
T=sc.nextInt();
for(int test_case = 1; test_case <= T; test_case++)
{
int N = sc.nextInt();
int[][] matrix = new int[N][N];
int[][] rotated90 = new int[N][N];
int[][] rotated180 = new int[N][N];
int[][] rotated270 = new int[N][N];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
matrix[i][j] = sc.nextInt();
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
rotated90[j][N-1-i] = matrix[i][j];
rotated180[N-1-i][N-1-j] = matrix[i][j];
rotated270[N-1-j][i] = matrix[i][j];
}
}
System.out.println("#" + test_case);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
System.out.print(rotated90[i][j]);
}
System.out.print(" ");
for (int j = 0; j < N; j++) {
System.out.print(rotated180[i][j]);
}
System.out.print(" ");
for (int j = 0; j < N; j++) {
System.out.print(rotated270[i][j]);
}
System.out.println();
}
}
}
}
Java들어가며 소프트웨어를 개발할 때 메모리 관리 방식은 프로그램의 안정성과 성능을 좌우하는 핵심 요소입니다. 특히 자바스크립트,…
들어가며 소프트웨어 개발자는 코드가 어떻게 실행되는지 정확히 이해해야 할 필요가 있습니다. 우리가 작성한 프로그램은 결국…
서론 현대 웹 애플리케이션 아키텍처에서 웹 서버(Web Server) 와 웹 애플리케이션 서버(WAS, Web Application Server)…
HTTP 헤더(Header)란? HTTP(Header)는 클라이언트와 서버 간에 교환되는 메타데이터로, 요청(Request)과 응답(Response)에 부가적인 정보를 실어 나르는 역할을…
Readable Code: 읽기 좋은 코드를 작성하는 사고법Practical Testing: 실용적인 테스트 가이드 강의와 함께한 인프런 워밍업 클럽…
Readable Code: 읽기 좋은 코드를 작성하는 사고법Practical Testing: 실용적인 테스트 가이드 강의와 함께한 인프런 워밍업 클럽…