-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
446 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <iostream> | ||
#include <stack> | ||
|
||
int main(void) | ||
{ | ||
std::ios_base::sync_with_stdio(false); | ||
std::cin.tie(NULL); | ||
|
||
int n; | ||
char ch; | ||
std::string str; | ||
std::stack <char> stk1, stk2; | ||
|
||
std::cin >> str >> n; | ||
for (int i = 0; i < str.size(); i++) stk1.push(str[i]); | ||
|
||
for (int i = 0; i < n; i++) { | ||
std::cin >> ch; | ||
if (ch == 'L' && !stk1.empty()) stk2.push(stk1.top()), stk1.pop(); | ||
else if (ch == 'D' && !stk2.empty()) stk1.push(stk2.top()), stk2.pop(); | ||
else if (ch == 'B' && !stk1.empty()) stk1.pop(); | ||
else if (ch == 'P') std::cin >> ch, stk1.push(ch); | ||
} | ||
|
||
while(stk1.size() > 0) stk2.push(stk1.top()), stk1.pop(); | ||
while(stk2.size() > 0) std::cout << stk2.top(), stk2.pop(); | ||
return 0; | ||
} |
37 changes: 37 additions & 0 deletions
37
YIM2UL2ET/์์ ์ ๋ฐ๋, ํฐ ์ ์ฐ์ฐ/9์ฐจ์ - BOJ 1914.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <iostream> | ||
|
||
std::string FindValue(int n) | ||
{ | ||
std::string result = "1"; | ||
for (int i = 0; i < n; i++) { | ||
for (int j = 0; j < result.size(); j++) { | ||
result[j] = (result[j] - '0') * 2 + '0'; | ||
if (result[j] > '9') { | ||
result[j] -= 10; | ||
if (j == 0) result.insert(result.begin(), '1'), j++; | ||
else result[j-1]++; | ||
} | ||
} | ||
} | ||
result[result.size()-1]--; | ||
return result; | ||
} | ||
|
||
void Hanoi(int level, int start, int between, int end) | ||
{ | ||
if (level == 1) std::cout << start << " " << end << "\n"; | ||
else { | ||
Hanoi(level-1, start, end, between); | ||
std::cout << start << " " << end << "\n"; | ||
Hanoi(level-1, between, start, end); | ||
} | ||
return; | ||
} | ||
|
||
int main(void) { | ||
int n; | ||
std::cin >> n; | ||
std::cout << FindValue(n) << "\n"; | ||
if (!(n > 20)) Hanoi(n, 1, 2, 3); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
def solution(s): | ||
answer = [] | ||
dic = {} | ||
s = s.replace('{','').replace('}','').split(',') | ||
|
||
for n in s: | ||
n = int(n) | ||
if n not in dic: | ||
dic[n] = 1 | ||
else: | ||
dic[n]+= 1 | ||
|
||
dic_sorted = sorted(dic.items(), key=lambda x:x[1], reverse=True) | ||
|
||
for d in dic_sorted: | ||
answer.append(d[0]) | ||
|
||
return answer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.*; | ||
|
||
public class BOJ1260_DFS์BFSํ๋ก๊ทธ๋จ { | ||
|
||
static ArrayList<Integer>[] edges; | ||
static boolean[] visited; | ||
static StringBuilder answer = new StringBuilder(); | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
int n = Integer.parseInt(st.nextToken()); // ๋ ธ๋ ์ | ||
int m = Integer.parseInt(st.nextToken()); // ๊ฐ์ ์ | ||
int v = Integer.parseInt(st.nextToken()); // ์ถ๋ฐ ๋ ธ๋ | ||
|
||
edges = new ArrayList[n + 1]; // ๊ฐ์ ๋ฐฐ์ด | ||
for (int i = 0; i < n + 1; i++) { | ||
edges[i] = new ArrayList<>(); | ||
} | ||
|
||
// ๊ฐ์ ์ฐ๊ฒฐ | ||
for (int i = 0; i < m; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
int a = Integer.parseInt(st.nextToken()); | ||
int b = Integer.parseInt(st.nextToken()); | ||
|
||
edges[a].add(b); | ||
edges[b].add(a); | ||
} | ||
|
||
for (int i = 0; i < n + 1; i++) { | ||
Collections.sort(edges[i]); | ||
} | ||
|
||
visited = new boolean[n + 1]; // ๋ฐฉ๋ฌธ ์ฌ๋ถ ๋ฐฐ์ด | ||
dfs(v); | ||
answer.append('\n'); | ||
|
||
visited = new boolean[n + 1]; | ||
bfs(v); | ||
answer.append('\n'); | ||
|
||
System.out.print(answer); | ||
} | ||
|
||
public static void dfs(int now) { | ||
answer.append(now); | ||
answer.append(' '); | ||
|
||
visited[now] = true; | ||
|
||
for (int next : edges[now]) { | ||
if (!visited[next]) { | ||
dfs(next); | ||
} | ||
} | ||
} | ||
|
||
public static void bfs(int start) { | ||
Queue<Integer> queue = new LinkedList<>(); | ||
|
||
// ์์ ๋ ธ๋ ์ฝ์ ํ๊ธฐ | ||
queue.add(start); | ||
visited[start] = true; | ||
|
||
// ํ๊ฐ ๋น๋๊น์ง ๋ฐ๋ณต | ||
while (!queue.isEmpty()) { | ||
int now = queue.poll(); | ||
answer.append(now); | ||
answer.append(' '); | ||
|
||
// now์ ์ฐ๊ฒฐ๋ node๋ค์ queue์ ์ฝ์ ํ๋ค. | ||
for (int next : edges[now]) { | ||
if (!visited[next]) { | ||
queue.add(next); | ||
visited[next] = true; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.LinkedList; | ||
import java.util.Queue; | ||
import java.util.StringTokenizer; | ||
|
||
public class BOJ2178_๋ฏธ๋กํ์ํ๊ธฐ { | ||
|
||
static int n; | ||
static int m; | ||
|
||
static boolean[][] field; | ||
static boolean[][] visited; | ||
|
||
static int[] dx = {1, -1, 0, 0}; | ||
static int[] dy = {0, 0, 1, -1}; | ||
public static void main(String[] args) throws IOException { | ||
// ์ ๋ ฅ | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
n = Integer.parseInt(st.nextToken()); // ์ธ๋ก ํฌ๊ธฐ | ||
m = Integer.parseInt(st.nextToken()); // ๊ฐ๋ก ํฌ๊ธฐ | ||
|
||
// ๋ฏธ๋ก ์ ์ธ | ||
field = new boolean[n][m]; | ||
visited = new boolean[n][m]; | ||
|
||
// ๋ฏธ๋ก ์ ๋ ฅ | ||
for (int i = 0; i < n; i++) { | ||
String line = br.readLine(); | ||
for (int j = 0; j < m; j++) { | ||
field[i][j] = line.charAt(j) == '1'; | ||
} | ||
} | ||
|
||
// ๋ฌธ์ ํด๊ฒฐ | ||
int answer = bfs(0, 0); | ||
|
||
// ์ถ๋ ฅ | ||
System.out.println(answer); | ||
} | ||
|
||
public static int bfs(int i, int j) { | ||
Queue<int[]> queue = new LinkedList<>(); | ||
queue.add(new int[]{i, j, 1}); | ||
visited[i][j] = true; | ||
|
||
while (!queue.isEmpty()) { | ||
int[] now = queue.poll(); | ||
|
||
if (now[0] == n - 1 && now[1] == m - 1) { | ||
return now[2]; | ||
} | ||
|
||
for (int k = 0; k < 4; k++) { | ||
int x = now[0] + dx[k]; | ||
int y = now[1] + dy[k]; | ||
|
||
if (isInRange(x, y)) { | ||
if (!visited[x][y] && field[x][y]) { | ||
queue.add(new int[]{x, y, now[2] + 1}); | ||
visited[x][y] = true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
public static boolean isInRange(int i, int j) { | ||
return 0 <= i && i < n && 0 <= j && j < m; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package DFS; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.StringTokenizer; | ||
|
||
public class BOJ1167_ํธ๋ฆฌ์์ง๋ฆ๊ตฌํ๊ธฐ { | ||
|
||
static ArrayList<Edge>[] edges; | ||
static boolean[] visited; | ||
static int max; | ||
static int farthest; | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
int V = Integer.parseInt(br.readLine()); | ||
edges = new ArrayList[V + 1]; | ||
for (int i = 0; i < V + 1; i++) { | ||
edges[i] = new ArrayList<>(); | ||
} | ||
|
||
for (int i = 0; i < V; i++) { | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
int a = Integer.parseInt(st.nextToken()); | ||
|
||
while (true) { | ||
int node = Integer.parseInt(st.nextToken()); | ||
if (node == -1) break; | ||
|
||
int cost = Integer.parseInt(st.nextToken()); | ||
edges[a].add(new Edge(node, cost)); | ||
} | ||
} | ||
|
||
max = 0; | ||
visited = new boolean[V+1]; | ||
dfs(1, 0); | ||
|
||
max = 0; | ||
visited = new boolean[V+1]; | ||
dfs(farthest, 0); | ||
|
||
System.out.println(max); | ||
} | ||
|
||
public static void dfs(int node, int cost) { | ||
visited[node] = true; | ||
if (cost > max) { | ||
farthest = node; | ||
max = cost; | ||
} | ||
|
||
for (Edge edge : edges[node]) { | ||
if (!visited[edge.node]) { | ||
dfs(edge.node, cost + edge.cost); | ||
} | ||
} | ||
} | ||
|
||
static class Edge { | ||
int node; | ||
int cost; | ||
|
||
public Edge(int node, int cost) { | ||
this.node = node; | ||
this.cost = cost; | ||
} | ||
} | ||
} |
Oops, something went wrong.