## 1501 1502는 너무 간단해서... import java.util.Scanner; public class CodeUp1501 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[][] arr = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { arr[i][j] = 1 + i * n + j; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { System.out.printf("%d ",arr[i][j]); } Sys..
PS - CodeUp
## 1411 기초 5-1 1차원 배열 빠진 카드 - 총 카드 수 N 입력받음 (1~N까지 있는 카드 묶음) - 하지만 한 장 잃어버림. 그 한장 빼고 다 입력받음. - 잃어버린 카드 찾기 import java.util.Scanner; public class CodeUp1411 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] arr = new int[N - 1]; for (int i = 0; i < N - 1; i++) { arr[i] = sc.nextInt(); } sc.close(); // outer: for (int cmp = 1; cmp
1441과 같은 버블 정렬이지만, 불필요한 단계는 스킵할 수 있는 알고리즘이 추가적으로 요구된다. 예를 들어 1 5 3 2 4 를 오름차순으로 정렬한다면, 1단계 - 1 3 2 4 5 2단계 - 1 2 3 4 5 (이미 정렬 완료) 3단계 - 1 2 3 4 5 4단계 - 1 2 3 4 5 불필요한 3 4단계는 반복문을 깨고 나와서 실행을 하지 않아야 함. ## 3011 위와 같음 총 몇 단계가 필요한지 출력하는 코드 import java.util.Scanner; public class CodeUp3011 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr =..
기초 5-3 2차원 배열 ## 1096 19*19의 바둑 판이 있다 > 바둑알 몇 개 놓을건지 입력 > 차례로 그만큼 좌표(두 수) 입력 > 바둑판 빈거 0 있는거 1로 출력 import java.util.Scanner; public class CodeUp1096 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[][] map = new int[19][19]; int n = sc.nextInt(); int[][] inp = new int[n][2]; for(int i = 0;i 좌표 해당하는 행과 열 전부를 뒤집음 (0은 1로 1은 0으로) import java.util.Scanner; public cla..
기초 5-1 1차원 배열 ## 1093 이상한 출석 1 1~23 사이를 몇번 부를건지 입력 > 그만큼 숫자를 입력 > 각 번호가 몇 번 불렸는지 출력 import java.util.Scanner; public class CodeUp1093 { public static void main(String[] args) { int[] num = new int[23]; Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] call = new int[n]; for (int i = 0; i < n; i++) { call[i] = sc.nextInt(); } sc.close(); for (int e : call) { num[e - 1]++; } for (in..
> 전에 C인가 Python인가 배울 때 정렬 관련해서 여러 알고리즘이 있다고 들었는데... 어떤 방법들이 있는지, 그리고 어떤 상황에서 어떤 방법이 빠른지 궁금했다. 나중에 배우게 될 지는 모르겠지만, 그냥 혼자 문제 풀면서 정리해봤다. 기초 5-4 데이터 정렬 ## 1441 버블 정렬 - 인접한 두 원소 검사, 작은 걸 앞으로. (오름차순) import java.util.Scanner; public class CodeUp1441 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] a = new int[10001]; int temp; int n = sc.nextInt(); // 개수 for (int i..
## 1099 기초 5-3 2차원 배열 성실한 개미 - 10*10의 판이 있음. 상하좌우는 모두 벽. - 벽은 1, 길은 0, 먹이는 2. 개미가 걸어가는 길은 9로 체크. - 개미는 (2,2)에서 출발 - 무조건 오른쪽으로, 오른쪽이 벽이면 아래로, 오른쪽과 아래가 벽이거나, 먹이를 찾으면 멈춤. - 멈출 때 까지 개미가 간 길을 9로 체크된 10*10으로 다시 출력. import java.util.Scanner; public class CodeUp1099 { public static void main(String[] args) { // 10*10 입력 Scanner sc = new Scanner(System.in); byte[][] map = new byte[10][10]; for (int i = 0..
## 1416 기초 5-1 1차원 배열 2진수 변환 import java.util.Scanner; public class CodeUp1416 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); byte[] arr = new byte[32]; for (int i = 31; i >= 0; i--) { if (n / (int) Math.pow(2, i) == 1) { arr[i]++; n -= (int) Math.pow(2, i); } } int first = 0; for (int i = 31; i >= 0; i--) { if (arr[i] == 1) first++; if (fir..
다 하긴 했는데 다 올리긴 좀 그렇고... 먼가 더 깔끔하게 할 수 있을까? 싶었던 것들을 올려본다. (1172 1274 1278 1380) ## 1172 세 수 정렬하기 import java.util.Scanner; public class CodeUp1172 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); if (a < b && a < c) { System.out.print(a + " "); if (b < c) System.out.print(b + " " + c); else System.out..