## 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]);
}
System.out.println();
}
}
}
import java.util.Scanner;
public class CodeUp1502 {
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[j][i] = 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]);
}
System.out.println();
}
}
}
- 다 똑같고 i랑 j만 바꿨나 그랬던 듯
## 1507
4개의 직사각형 넓이
- 4 개의 직사각형이 주어진다. 입력 형식은: x1 y1 x2 y2이고, 좌상단 좌표가 x1 y1, 우하단 좌표가 x2 y2 이런식
- 0<=평면 범위<100
- 차지하는 넓이를 구하라
import java.util.Scanner;
public class CodeUp1507 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[][] arr = new int[4][4];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
arr[i][j] = sc.nextInt();
}
}
boolean[][] map = new boolean[100][100];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < arr[i][2] - arr[i][0]; j++) {
for (int k = 0; k < arr[i][3] - arr[i][1]; k++) {
map[arr[i][0]+j][arr[i][1]+k] = true;
}
}
}
int sum = 0;
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
if(map[i][j]==true)
sum++;
}
}
System.out.println(sum);
}
}
- 첨엔 이거 어케하지... 했는데 잘 생각하면 쉽다
- ㅁㅁ
ㅁㅁ 이렇게 있다면... 각 ㅁ의 좌상단 좌표가 ㅁ을 대표해서 넓이 1이라고 생각하면 편하다.
## 1512
숫자 등고선
- 첫 입력은 n*n 크기의 맵을 만들 때의 n
- 두번째 입력은 두 수, 1이 있을 좌표
- 1 주위로 숫자가 점점 커지는 걸 출력
ex) 3 2 3
2 1 2
3 2 3
import java.util.Scanner;
public class CodeUp1512 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[][] map = new int[n][n];
int r = sc.nextInt() - 1;
int c = sc.nextInt() - 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
map[i][j] = Math.abs(r - i) + Math.abs(c - j) + 1;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.printf("%d ", map[i][j]);
}
System.out.println();
}
}
}
- 엄,,, 어렵지 않았고.
- 두 포문을 하나로 합쳤어도 됐겠다는 생각이 드네.
'PS - CodeUp' 카테고리의 다른 글
1411, 1492 - 빠진 카드, 1차원 누적 합 배열 만들기 (결국 둘 다 새로 짬) (0) | 2022.01.20 |
---|---|
3011 - 버블 정렬 + (0) | 2022.01.20 |
1096, 1097, 1098 - 바둑판에 흰 돌 놓기, 바둑알 십자 뒤집기, 설탕과자 뽑기 (0) | 2022.01.20 |
1093, 1094, 1095 - 이상한 출석 번호 부르기 1, 2, 3 (0) | 2022.01.20 |
1441, 1442, 1443 - 버블 정렬, 선택 정렬, 삽입 정렬 (0) | 2022.01.20 |