티스토리 뷰
1093 : [기초-1차원배열] 이상한 출석 번호 부르기1
import java.util.Scanner;
// 210124
// 1093 : [기초-1차원배열] 이상한 출석 번호 부르기1
public class CU1093 {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int[] stu = new int[24]; // 학생 23명
for (int i = 0; i < num; i++) {
stu[sc.nextInt()] += 1;
}
for (int i = 1; i < stu.length; i++) {
System.out.print(stu[i] + " ");
}
sc.close();
}
}
1094 : [기초-1차원배열] 이상한 출석 번호 부르기2
import java.util.Scanner;
// 210124
// 1094 : [기초-1차원배열] 이상한 출석 번호 부르기2
public class CU1094 {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int[] stuArr = new int[num];
for (int i = 0; i < num; i++) {
stuArr[i] = sc.nextInt();
}
for (int i = num -1; i>=0; i--) {
System.out.print(stuArr[i] + " ");
}
sc.close();
}
}
1095 : [기초-1차원배열] 이상한 출석 번호 부르기3
import java.util.Scanner;
// 210124
// 1095 : [기초-1차원배열] 이상한 출석 번호 부르기3
public class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int min = 2147000000;
for (int i=0; i<num; i++) {
int stuNum = sc.nextInt();
if (min > stuNum) min = stuNum;
}
System.out.println(min);
sc.close();
}
}
1096 : [기초-2차원배열] 바둑판에 흰 돌 놓기
import java.util.Scanner;
// 210124
// 1096 : [기초-2차원배열] 바둑판에 흰 돌 놓기
public class CU1096 {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int[][] intArr = new int[20][20];
for (int i=0; i<num; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
intArr[x][y] = 1;
}
for (int i=1; i<intArr.length; i++) {
for (int j=1; j<intArr[i].length; j++) {
System.out.print(intArr[i][j] + " ");
}
System.out.println();
}
sc.close();
}
}
1097 : [기초-2차원배열] 바둑알 십자 뒤집기
import java.util.Scanner;
// 210124
// 1097 : [기초-2차원배열] 바둑알 십자 뒤집기
public class CU1097 {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int[][] intArr = new int[20][20];
for (int i=1; i<=19; i++) {
for (int j=1; j<=19; j++) {
intArr[i][j] = sc.nextInt();
}
}
int num = sc.nextInt();
for (int i=1; i<=num; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
// 가로줄 뒤집기
for (int col = 1; col<=19; col++) {
intArr[x][col] = (intArr[x][col] == 0) ? 1: 0;
}
// 세로줄 뒤집기
for (int row = 1; row<=19; row++) {
intArr[row][y] = (intArr[row][y] == 0) ? 1: 0;
}
}
// 출력
for (int i=1; i<=19; i++) {
for (int j=1; j<=19; j++) {
System.out.print(intArr[i][j] + " ");
}
System.out.println();
}
sc.close();
}
}
1098 : [기초-2차원배열] 설탕과자 뽑기
import java.util.Scanner;
// 210125
// 1098 : [기초-2차원배열] 설탕과자 뽑기
public class CU1098 {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int h = sc.nextInt(); // 세로
int w = sc.nextInt(); // 가로
int n = sc.nextInt(); // 막대 개수
int[][] myMap = new int[h+1][w+1];
for (int i=1; i<=n; i++) {
int l = sc.nextInt(); // 길이
int d = sc.nextInt(); // 방향 0->우, 1-> 하
int x = sc.nextInt(); // x
int y = sc.nextInt(); // y
for (int j=0; j<l; j++) { // 길이만큼
if (d == 0) {
myMap[x][y+j] = 1;
} else if (d == 1) {
myMap[x+j][y] = 1;
}
}
}
// 출력
for (int i=1; i<=h; i++) {
for (int j=1; j<=w; j++) {
System.out.print(myMap[i][j] + " ");
}
System.out.println();
}
sc.close();
}
}
1099 : [기초-2차원배열] 성실한 개미
import java.util.Scanner;
// 210125
// 1099 : [기초-2차원배열] 성실한 개미
public class CU1099 {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int[][] myMap = new int[11][11];
for (int i=1; i<=10; i++) {
for (int j=1; j<=10; j++) {
myMap[i][j] = sc.nextInt();
}
}
// 이동
int i = 2;
int j = 2;
while ((i < 10) && (j < 10)) {
if (myMap[i][j] == 2) {
myMap[i][j] = 9;
break; // 먹이를 찾음
} else if (myMap[i][j] == 0) {
myMap[i][j] = 9;
}
if (myMap[i][j+1] != 1) j += 1;
else if (myMap[i+1][j] != 1) i += 1;
else break; // 끝까지 탐색
} // while
// 출력
i = 1;
j = 1;
for (i=1; i<=10; i++) {
for (j=1; j<=10; j++) {
System.out.print(myMap[i][j] + " ");
}
System.out.println();
}
sc.close();
}
}
'코딩테스트 > 코드업' 카테고리의 다른 글
[CodeUp] 100제 - 1053 ~ 1062 (0) | 2021.01.25 |
---|---|
[CodeUp] 1515 : 생명 게임 1 (0) | 2021.01.25 |
[CodeUp] 100제 - 1087 ~ 1092 (0) | 2021.01.23 |
[CodeUp] 100제 - 1085, 1086 (0) | 2021.01.23 |
[CodeUp] 100제 - 1084 : [기초-종합] 빛 섞어 색 만들기 (0) | 2021.01.22 |
댓글