반응형
# 1097
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[][] arr = new int[19][19];
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length; j++) {
arr[i][j] = sc.nextInt();
}
}
int n = sc.nextInt();
int x, y;
for (int i = 0; i < n; i++) {
x = sc.nextInt();
for (int j = 0; j < arr.length; j++) {
if (arr[x - 1][j] == 0) {
arr[x - 1][j] = 1;
} else {
arr[x - 1][j] = 0;
}
}
y = sc.nextInt();
for (int k = 0; k < arr.length; k++) {
if (arr[k][y - 1] == 0) {
arr[k][y - 1] = 1;
} else {
arr[k][y - 1] = 0;
}
}
}
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length; j++) {
System.out.printf(arr[i][j] + " ");
}
System.out.println();
}
}
}
# 1098
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int X = sc.nextInt();
int Y = sc.nextInt();
int[][] arr = new int[X + 1][Y + 1];
int n = sc.nextInt();
int l, d, x, y;
for (int i = 0; i < n; i++) {
l = sc.nextInt();
d = sc.nextInt();
x = sc.nextInt();
y = sc.nextInt();
if (d == 0) {
for (int j = 0; j < l; j++) {
arr[x][y + j] = 1;
}
} else if (d == 1) {
for (int k = 0; k < l; k++) {
arr[x + k][y] = 1;
}
}
}
for (int i = 1; i <= X; i++) {
for (int j = 1; j <= Y; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}
# 1099
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[][] arr = new int[11][11];
for (int i = 1; i < arr.length; i++) {
String a = sc.nextLine();
String[] b = a.split(" ");
for (int j = 0; j < arr.length - 1; j++) {
arr[i][j + 1] = Integer.parseInt(b[j]);
}
}
int x = 2;
int y = 2;
while (true) {
if (arr[x][y] == 2) {
arr[x][y] = 9;
break;
}
if (arr[x][y + 1] == 1) {
if (arr[x + 1][y] == 1) {
break;
} else {
x++;
}
} else if (arr[x][y + 1] != 1) {
y++;
}
if (arr[x][y] == 2) {
arr[x][y] = 9;
break;
}
arr[x][y] = 9;
}
arr[2][2] = 9;
for (int i = 1; i < arr.length; i++) {
for (int j = 1; j < arr.length; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}
반응형
'개인 공부 > JAVA' 카테고리의 다른 글
[Java/Spring] DAO vs DTO vs VO (0) | 2021.07.03 |
---|---|
[Java/Spring] JAR와 WAR의 차이 (0) | 2021.07.02 |
[JAVA] Code Up 기초 100제 (1093~ 1096) (0) | 2021.06.27 |
[JAVA] Code Up 기초 100제 (1088 ~ 1092) (0) | 2021.06.26 |
[JAVA] Code Up 기초 100제 (1083 ~ 1087) (0) | 2021.06.25 |