Skip to content

Commit f88732e

Browse files
committed
Update
1 parent 6745b7c commit f88732e

File tree

14 files changed

+1090
-0
lines changed

14 files changed

+1090
-0
lines changed

Diff for: โ€Ž12/1.java

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java.util.*;
2+
3+
public class Main {
4+
5+
public static String str;
6+
public static int summary = 0;
7+
8+
public static void main(String[] args) {
9+
Scanner sc = new Scanner(System.in);
10+
str = sc.next();
11+
12+
// ์™ผ์ชฝ ๋ถ€๋ถ„์˜ ์ž๋ฆฟ์ˆ˜์˜ ํ•ฉ ๋”ํ•˜๊ธฐ
13+
for (int i = 0; i < str.length() / 2; i++) {
14+
summary += str.charAt(i) - '0';
15+
}
16+
17+
// ์˜ค๋ฅธ์ชฝ ๋ถ€๋ถ„์˜ ์ž๋ฆฟ์ˆ˜์˜ ํ•ฉ ๋นผ๊ธฐ
18+
for (int i = str.length() / 2; i < str.length(); i++) {
19+
summary -= str.charAt(i) - '0';
20+
}
21+
22+
// ์™ผ์ชฝ ๋ถ€๋ถ„๊ณผ ์˜ค๋ฅธ์ชฝ ๋ถ€๋ถ„์˜ ์ž๋ฆฟ์ˆ˜ ํ•ฉ์ด ๋™์ผํ•œ์ง€ ๊ฒ€์‚ฌ
23+
if (summary == 0) System.out.println("LUCKY");
24+
else System.out.println("READY");
25+
}
26+
}

Diff for: โ€Ž12/2.java

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import java.util.*;
2+
3+
public class Main {
4+
5+
public static String str;
6+
public static ArrayList<Character> result = new ArrayList<Character>();
7+
public static int value = 0;
8+
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
str = sc.next();
12+
13+
// ๋ฌธ์ž๋ฅผ ํ•˜๋‚˜์”ฉ ํ™•์ธํ•˜๋ฉฐ
14+
for (int i = 0; i < str.length(); i++) {
15+
// ์•ŒํŒŒ๋ฒณ์ธ ๊ฒฝ์šฐ ๊ฒฐ๊ณผ ๋ฆฌ์ŠคํŠธ์— ์‚ฝ์ž…
16+
if (Character.isLetter(str.charAt(i))) {
17+
result.add(str.charAt(i));
18+
}
19+
// ์ˆซ์ž๋Š” ๋”ฐ๋กœ ๋”ํ•˜๊ธฐ
20+
else {
21+
value += str.charAt(i) - '0';
22+
}
23+
}
24+
25+
// ์•ŒํŒŒ๋ฒณ์„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ
26+
Collections.sort(result);
27+
28+
// ์•ŒํŒŒ๋ฒณ์„ ์ฐจ๋ก€๋Œ€๋กœ ์ถœ๋ ฅ
29+
for (int i = 0; i < result.size(); i++) {
30+
System.out.print(result.get(i));
31+
}
32+
33+
// ์ˆซ์ž๊ฐ€ ํ•˜๋‚˜๋ผ๋„ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ ๊ฐ€์žฅ ๋’ค์— ์ถœ๋ ฅ
34+
if (value != 0) System.out.print(value);
35+
System.out.println();
36+
}
37+
}

Diff for: โ€Ž12/3.java

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
5+
public int solution(String s) {
6+
int answer = s.length();
7+
// 1๊ฐœ ๋‹จ์œ„(step)๋ถ€ํ„ฐ ์••์ถ• ๋‹จ์œ„๋ฅผ ๋Š˜๋ ค๊ฐ€๋ฉฐ ํ™•์ธ
8+
for (int step = 1; step < s.length() / 2 + 1; step++) {
9+
String compressed = "";
10+
String prev = s.substring(0, step); // ์•ž์—์„œ๋ถ€ํ„ฐ step๋งŒํผ์˜ ๋ฌธ์ž์—ด ์ถ”์ถœ
11+
int cnt = 1;
12+
// ๋‹จ์œ„(step) ํฌ๊ธฐ๋งŒํผ ์ฆ๊ฐ€์‹œํ‚ค๋ฉฐ ์ด์ „ ๋ฌธ์ž์—ด๊ณผ ๋น„๊ต
13+
for (int j = step; j < s.length(); j += step) {
14+
// ์ด์ „ ์ƒํƒœ์™€ ๋™์ผํ•˜๋‹ค๋ฉด ์••์ถ• ํšŸ์ˆ˜(count) ์ฆ๊ฐ€
15+
String sub = "";
16+
for (int k = j; k < j + step; k++) {
17+
if (k < s.length()) sub += s.charAt(k);
18+
}
19+
if (prev.equals(sub)) cnt += 1;
20+
// ๋‹ค๋ฅธ ๋ฌธ์ž์—ด์ด ๋‚˜์™”๋‹ค๋ฉด(๋” ์ด์ƒ ์••์ถ•ํ•˜์ง€ ๋ชปํ•˜๋Š” ๊ฒฝ์šฐ๋ผ๋ฉด)
21+
else {
22+
compressed += (cnt >= 2)? cnt + prev : prev;
23+
sub = "";
24+
for (int k = j; k < j + step; k++) {
25+
if (k < s.length()) sub += s.charAt(k);
26+
}
27+
prev = sub; // ๋‹ค์‹œ ์ƒํƒœ ์ดˆ๊ธฐํ™”
28+
cnt = 1;
29+
}
30+
}
31+
// ๋‚จ์•„์žˆ๋Š” ๋ฌธ์ž์—ด์— ๋Œ€ํ•ด์„œ ์ฒ˜๋ฆฌ
32+
compressed += (cnt >= 2)? cnt + prev : prev;
33+
// ๋งŒ๋“ค์–ด์ง€๋Š” ์••์ถ• ๋ฌธ์ž์—ด์ด ๊ฐ€์žฅ ์งง์€ ๊ฒƒ์ด ์ •๋‹ต
34+
answer = Math.min(answer, compressed.length());
35+
}
36+
return answer;
37+
}
38+
}

Diff for: โ€Ž12/4.java

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
5+
// 2์ฐจ์› ๋ฆฌ์ŠคํŠธ 90๋„ ํšŒ์ „ํ•˜๊ธฐ
6+
public static int[][] rotateMatrixBy90Degree(int[][] a) {
7+
int n = a.length;
8+
int m = a[0].length;
9+
int[][] result = new int[n][m]; // ๊ฒฐ๊ณผ ๋ฆฌ์ŠคํŠธ
10+
for (int i = 0; i < n; i++) {
11+
for (int j = 0; j < m; j++) {
12+
result[j][n - i - 1] = a[i][j];
13+
}
14+
}
15+
return result;
16+
}
17+
18+
// ์ž๋ฌผ์‡ ์˜ ์ค‘๊ฐ„ ๋ถ€๋ถ„์ด ๋ชจ๋‘ 1์ธ์ง€ ํ™•์ธ
19+
public static boolean check(int[][] newLock) {
20+
int lockLength = newLock.length / 3;
21+
for (int i = lockLength; i < lockLength * 2; i++) {
22+
for (int j = lockLength; j < lockLength * 2; j++) {
23+
if (newLock[i][j] != 1) {
24+
return false;
25+
}
26+
}
27+
}
28+
return true;
29+
}
30+
31+
public boolean solution(int[][] key, int[][] lock) {
32+
int n = lock.length;
33+
int m = key.length;
34+
// ์ž๋ฌผ์‡ ์˜ ํฌ๊ธฐ๋ฅผ ๊ธฐ์กด์˜ 3๋ฐฐ๋กœ ๋ณ€ํ™˜
35+
int[][] newLock = new int[n * 3][n * 3];
36+
// ์ƒˆ๋กœ์šด ์ž๋ฌผ์‡ ์˜ ์ค‘์•™ ๋ถ€๋ถ„์— ๊ธฐ์กด์˜ ์ž๋ฌผ์‡  ๋„ฃ๊ธฐ
37+
for (int i = 0; i < n; i++) {
38+
for (int j = 0; j < n; j++) {
39+
newLock[i + n][j + n] = lock[i][j];
40+
}
41+
}
42+
43+
// 4๊ฐ€์ง€ ๋ฐฉํ–ฅ์— ๋Œ€ํ•ด์„œ ํ™•์ธ
44+
for (int rotation = 0; rotation < 4; rotation++) {
45+
key = rotateMatrixBy90Degree(key); // ์—ด์‡  ํšŒ์ „
46+
for (int x = 0; x < n * 2; x++) {
47+
for (int y = 0; y < n * 2; y++) {
48+
// ์ž๋ฌผ์‡ ์— ์—ด์‡ ๋ฅผ ๋ผ์›Œ ๋„ฃ๊ธฐ
49+
for (int i = 0; i < m; i++) {
50+
for (int j = 0; j < m; j++) {
51+
newLock[x + i][y + j] += key[i][j];
52+
}
53+
}
54+
// ์ƒˆ๋กœ์šด ์ž๋ฌผ์‡ ์— ์—ด์‡ ๊ฐ€ ์ •ํ™•ํžˆ ๋“ค์–ด ๋งž๋Š”์ง€ ๊ฒ€์‚ฌ
55+
if (check(newLock)) return true;
56+
// ์ž๋ฌผ์‡ ์—์„œ ์—ด์‡ ๋ฅผ ๋‹ค์‹œ ๋นผ๊ธฐ
57+
for (int i = 0; i < m; i++) {
58+
for (int j = 0; j < m; j++) {
59+
newLock[x + i][y + j] -= key[i][j];
60+
}
61+
}
62+
}
63+
}
64+
}
65+
return false;
66+
}
67+
}

Diff for: โ€Ž12/5.java

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import java.util.*;
2+
3+
class Node {
4+
5+
private int time;
6+
private char direction;
7+
8+
public Node(int time, char direction) {
9+
this.time = time;
10+
this.direction = direction;
11+
}
12+
13+
public int getTime() {
14+
return this.time;
15+
}
16+
17+
public char getDirection() {
18+
return this.direction;
19+
}
20+
}
21+
22+
class Position {
23+
24+
private int x;
25+
private int y;
26+
27+
public Position(int x, int y) {
28+
this.x = x;
29+
this.y = y;
30+
}
31+
32+
public int getX() {
33+
return this.x;
34+
}
35+
36+
public int getY() {
37+
return this.y;
38+
}
39+
}
40+
41+
public class Main {
42+
43+
public static int n, k, l;
44+
public static int[][] arr = new int[101][101]; // ๋งต ์ •๋ณด
45+
public static ArrayList<Node> info = new ArrayList<>(); // ๋ฐฉํ–ฅ ํšŒ์ „ ์ •๋ณด
46+
47+
// ์ฒ˜์Œ์—๋Š” ์˜ค๋ฅธ์ชฝ์„ ๋ณด๊ณ  ์žˆ์œผ๋ฏ€๋กœ(๋™, ๋‚จ, ์„œ, ๋ถ)
48+
public static int dx[] = {0, 1, 0, -1};
49+
public static int dy[] = {1, 0, -1, 0};
50+
51+
public static int turn(int direction, char c) {
52+
if (c == 'L') direction = (direction == 0)? 3 : direction - 1;
53+
else direction = (direction + 1) % 4;
54+
return direction;
55+
}
56+
57+
public static int simulate() {
58+
int x = 1, y = 1; // ๋ฑ€์˜ ๋จธ๋ฆฌ ์œ„์น˜
59+
arr[x][y] = 2; // ๋ฑ€์ด ์กด์žฌํ•˜๋Š” ์œ„์น˜๋Š” 2๋กœ ํ‘œ์‹œ
60+
int direction = 0; // ์ฒ˜์Œ์—๋Š” ๋™์ชฝ์„ ๋ณด๊ณ  ์žˆ์Œ
61+
int time = 0; // ์‹œ์ž‘ํ•œ ๋’ค์— ์ง€๋‚œ '์ดˆ' ์‹œ๊ฐ„
62+
int index = 0; // ๋‹ค์Œ์— ํšŒ์ „ํ•  ์ •๋ณด
63+
// ๋ฑ€์ด ์ฐจ์ง€ํ•˜๊ณ  ์žˆ๋Š” ์œ„์น˜ ์ •๋ณด(๊ผฌ๋ฆฌ๊ฐ€ ์•ž์ชฝ)
64+
Queue<Position> q = new LinkedList<>();
65+
q.offer(new Position(x, y));
66+
67+
while (true) {
68+
int nx = x + dx[direction];
69+
int ny = y + dy[direction];
70+
// ๋งต ๋ฒ”์œ„ ์•ˆ์— ์žˆ๊ณ , ๋ฑ€์˜ ๋ชธํ†ต์ด ์—†๋Š” ์œ„์น˜๋ผ๋ฉด
71+
if (1 <= nx && nx <= n && 1 <= ny && ny <= n && arr[nx][ny] != 2) {
72+
// ์‚ฌ๊ณผ๊ฐ€ ์—†๋‹ค๋ฉด ์ด๋™ ํ›„์— ๊ผฌ๋ฆฌ ์ œ๊ฑฐ
73+
if (arr[nx][ny] == 0) {
74+
arr[nx][ny] = 2;
75+
q.offer(new Position(nx, ny));
76+
Position prev = q.poll();
77+
arr[prev.getX()][prev.getY()] = 0;
78+
}
79+
// ์‚ฌ๊ณผ๊ฐ€ ์žˆ๋‹ค๋ฉด ์ด๋™ ํ›„์— ๊ผฌ๋ฆฌ ๊ทธ๋Œ€๋กœ ๋‘๊ธฐ
80+
if (arr[nx][ny] == 1) {
81+
arr[nx][ny] = 2;
82+
q.offer(new Position(nx, ny));
83+
}
84+
}
85+
// ๋ฒฝ์ด๋‚˜ ๋ฑ€์˜ ๋ชธํ†ต๊ณผ ๋ถ€๋”ชํ˜”๋‹ค๋ฉด
86+
else {
87+
time += 1;
88+
break;
89+
}
90+
// ๋‹ค์Œ ์œ„์น˜๋กœ ๋จธ๋ฆฌ๋ฅผ ์ด๋™
91+
x = nx;
92+
y = ny;
93+
time += 1;
94+
if (index < l && time == info.get(index).getTime()) { // ํšŒ์ „ํ•  ์‹œ๊ฐ„์ธ ๊ฒฝ์šฐ ํšŒ์ „
95+
direction = turn(direction, info.get(index).getDirection());
96+
index += 1;
97+
}
98+
}
99+
return time;
100+
}
101+
102+
public static void main(String[] args) {
103+
Scanner sc = new Scanner(System.in);
104+
105+
n = sc.nextInt();
106+
k = sc.nextInt();
107+
108+
// ๋งต ์ •๋ณด(์‚ฌ๊ณผ ์žˆ๋Š” ๊ณณ์€ 1๋กœ ํ‘œ์‹œ)
109+
for (int i = 0; i < k; i++) {
110+
int a = sc.nextInt();
111+
int b = sc.nextInt();
112+
arr[a][b] = 1;
113+
}
114+
115+
// ๋ฐฉํ–ฅ ํšŒ์ „ ์ •๋ณด ์ž…๋ ฅ
116+
l = sc.nextInt();
117+
for (int i = 0; i < l; i++) {
118+
int x = sc.nextInt();
119+
char c = sc.next().charAt(0);
120+
info.add(new Node(x, c));
121+
}
122+
123+
System.out.println(simulate());
124+
}
125+
126+
}

Diff for: โ€Ž17/1.java

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import java.util.*;
2+
3+
public class Main {
4+
5+
public static final int INF = (int) 1e9; // ๋ฌดํ•œ์„ ์˜๋ฏธํ•˜๋Š” ๊ฐ’์œผ๋กœ 10์–ต์„ ์„ค์ •
6+
// ๋…ธ๋“œ์˜ ๊ฐœ์ˆ˜(N), ๊ฐ„์„ ์˜ ๊ฐœ์ˆ˜(M)
7+
public static int n, m;
8+
// 2์ฐจ์› ๋ฐฐ์—ด(๊ทธ๋ž˜ํ”„ ํ‘œํ˜„)๋ฅผ ๋งŒ๋“ค๊ธฐ
9+
public static int[][] graph = new int[101][101];
10+
11+
public static void main(String[] args) {
12+
Scanner sc = new Scanner(System.in);
13+
14+
n = sc.nextInt();
15+
m = sc.nextInt();
16+
17+
// ์ตœ๋‹จ ๊ฑฐ๋ฆฌ ํ…Œ์ด๋ธ”์„ ๋ชจ๋‘ ๋ฌดํ•œ์œผ๋กœ ์ดˆ๊ธฐํ™”
18+
for (int i = 0; i < 101; i++) {
19+
Arrays.fill(graph[i], INF);
20+
}
21+
22+
// ์ž๊ธฐ ์ž์‹ ์—์„œ ์ž๊ธฐ ์ž์‹ ์œผ๋กœ ๊ฐ€๋Š” ๋น„์šฉ์€ 0์œผ๋กœ ์ดˆ๊ธฐํ™”
23+
for (int a = 1; a <= n; a++) {
24+
for (int b = 1; b <= n; b++) {
25+
if (a == b) graph[a][b] = 0;
26+
}
27+
}
28+
29+
// ๊ฐ ๊ฐ„์„ ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์ž…๋ ฅ ๋ฐ›์•„, ๊ทธ ๊ฐ’์œผ๋กœ ์ดˆ๊ธฐํ™”
30+
for (int i = 0; i < m; i++) {
31+
// A์—์„œ B๋กœ ๊ฐ€๋Š” ๋น„์šฉ์€ C๋ผ๊ณ  ์„ค์ •
32+
int a = sc.nextInt();
33+
int b = sc.nextInt();
34+
int c = sc.nextInt();
35+
// ๊ฐ€์žฅ ์งง์€ ๊ฐ„์„  ์ •๋ณด๋งŒ ์ €์žฅ
36+
if (c < graph[a][b]) graph[a][b] = c;
37+
}
38+
39+
// ์ ํ™”์‹์— ๋”ฐ๋ผ ํ”Œ๋กœ์ด๋“œ ์›Œ์…œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ˆ˜ํ–‰
40+
for (int k = 1; k <= n; k++) {
41+
for (int a = 1; a <= n; a++) {
42+
for (int b = 1; b <= n; b++) {
43+
graph[a][b] = Math.min(graph[a][b], graph[a][k] + graph[k][b]);
44+
}
45+
}
46+
}
47+
48+
// ์ˆ˜ํ–‰๋œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅ
49+
for (int a = 1; a <= n; a++) {
50+
for (int b = 1; b <= n; b++) {
51+
// ๋„๋‹ฌํ•  ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ, ๋ฌดํ•œ(INFINITY)์ด๋ผ๊ณ  ์ถœ๋ ฅ
52+
if (graph[a][b] == INF) {
53+
System.out.print(0 + " ");
54+
}
55+
// ๋„๋‹ฌํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ ๊ฑฐ๋ฆฌ๋ฅผ ์ถœ๋ ฅ
56+
else {
57+
System.out.print(graph[a][b] + " ");
58+
}
59+
}
60+
System.out.println();
61+
}
62+
}
63+
}

0 commit comments

Comments
ย (0)