issues
search
2024-TEAM-05
/
algorithm-for-kakao
์นด์นด์ค ๊ธฐ์ถ ๋ฌธ์ ๊ฐ์ฆ์๐ฃ
0
stars
0
forks
source link
[2023 KAKAO BLIND RECRUITMENT] ํ ๋ณํฉ
#11
Open
uijin-j
opened
2 months ago
uijin-j
commented
2 months ago
๐
ํ ๋ณํฉ
hye-on
commented
2 months ago
๐ ๋๊ธ ํ ํ๋ฆฟ
Language : C++
์ฑ๋ฅ
์ฝ๋ ํ์ด
```cpp #include
#include
#include
#include
using namespace std; //11:23 ~ 1:04 ๋ถ // ๊ตฌํ? // ์์น ๊ฐ์ง๊ณ ์๋ ๋ฐฐ์ด a , ๊ฐ ๊ฐ์ง๊ณ ์๋ ๋ฐฐ์ด b //update - b ๊ฐ ์ฝ์ //update - b ๊ฐ ๊ต์ฒด //Merge - r2,c2์ ๋ค r1,c1์ ๋ฃ์ด์ค // - ๊ฐ์ a๋ฅผ ์ฐธ๊ณ ํด์ r1,c1๊ฒ์ผ๋ก ๋ค b์ ๋ฃ์ด์ค ๋น์ด ์์ผ๋ฉด r2,c2๊บผ //Unmerge - a์์ r,c์ ์๋ point์ ์๋ ๊ฐ๊ณผ ์ผ์นํ๋๊ฑฐ ๋ค ํด์ . ๊ฐ์์ผ๋ฉด r,c์๋ง ๋ฃ์ด์ค pair
p[51][51]; string map[51][51]; vector
token; string word; void update(string cmd){ int idx = cmd.find(' '); string t = cmd.substr(idx+1); vector
tokens = token; stringstream ss(t); // ์ ๋ ฅ์ ๊ณต๋ฐฑ์ผ๋ก ๋ถ๋ฆฌ while (ss >> word) { tokens.push_back(word); } //cout<
solution(vector
commands) { vector
answer; //์ด๊ธฐํ for(int i=1;i<=50;i++){ for(int j=1;j<=50;j++){ p[i][j] = {to_string(i),to_string(j)}; } } for(int i=0;i
์ฝ๋ฉํธ
- ์คํ ํ๋ ๋๋ฌธ์ 30๋ถ ๊ฑธ๋ ธ๋ค์.. - updateํ ๋ string ํ์ฑํ๋ ๋ถ๋ถ์ด ์ด๋ ค์ ์ต๋๋ค.
uijin-j
commented
2 months ago
๐ ๋๊ธ ํ ํ๋ฆฟ
Language : Java
์ฑ๋ฅ
์ฝ๋ ํ์ด
```java import java.util.*; // 17:25 START! // ์ ๋์จํ์ธ๋? class Solution { int[] parents; String[] values; public String[] solution(String[] commands) { List
printedList = new ArrayList<>(); parents = new int[2501]; values = new String[2501]; for(int i = 1; i <= 2500; ++i) { parents[i] = i; values[i] = ""; } for(String command : commands) { String[] args = command.split(" "); String cmd = args[0]; if(cmd.equals("UPDATE") && args.length == 4) { int x = Integer.parseInt(args[1]); int y = Integer.parseInt(args[2]); int point = getPoint(x, y); values[find(point)] = args[3]; continue; } if(cmd.equals("UPDATE")) { String from = args[1]; String to = args[2]; for(int point = 1; point <= 2500; ++point) { if(values[find(point)].equals(from)) { values[find(point)] = to; } } continue; } if(cmd.equals("MERGE")) { int x1 = Integer.parseInt(args[1]); int y1 = Integer.parseInt(args[2]); int x2 = Integer.parseInt(args[3]); int y2 = Integer.parseInt(args[4]); int from = getPoint(x1, y1); int to = getPoint(x2, y2); union(from, to); continue; } if(cmd.equals("UNMERGE")) { int x = Integer.parseInt(args[1]); int y = Integer.parseInt(args[2]); int point = getPoint(x, y); int target = find(point); String before = values[find(point)]; boolean[] check = new boolean[2501]; for(int i = 1; i <= 2500; ++i) { if(find(i) == target) { check[i] = true; } } for(int i = 1; i <= 2500; ++i) { if(check[i]) parents[i] = i; } values[target] = ""; values[point] = before; continue; } if(cmd.equals("PRINT")) { int x = Integer.parseInt(args[1]); int y = Integer.parseInt(args[2]); int point = (x - 1) * 50 + y; String toPrint = values[find(point)].isBlank() ? "EMPTY" : values[find(point)]; printedList.add(toPrint); continue; } } String[] answer = new String[printedList.size()]; for(int i = 0; i < printedList.size(); ++i) { answer[i] = printedList.get(i); } return answer; } public int find(int point) { if(parents[point] == point) return point; return parents[point] = find(parents[point]); } public void union(int p1, int p2) { int parent1 = find(p1); int parent2 = find(p2); if(parent1 == parent2) return; String value = (values[parent1].isBlank()) ? values[parent2] : values[parent1]; parents[parent2] = parent1; values[parent1] = value; values[parent2] = ""; } public int getPoint(int x, int y) { return (x - 1) * 50 + y; } } ```
์ฝ๋ฉํธ
๐ ํ ๋ณํฉ