PS/boj
-
boj)1874 - 스택 수열PS/boj 2020. 9. 13. 23:41
import java.io.*; import java.util.Stack; public class boj_1874 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); Stack s = new Stack(); int n = Integer.parseInt(br.readLine()); // 1 ~ 100,000 int item = 0; // 스택에 오름차순으로 쌓일 수 while (n-- > 0) { int x = Integer.parseInt(br...
-
boj)9012 - 괄호PS/boj 2020. 9. 13. 19:15
import java.io.*; public class boj_9012 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int T = Integer.parseInt(br.readLine()); for (int i = 0; i < T; i++) { String str = br.readLine(); int temp = 0; for (int j = 0; j < str.length();..
-
boj)9093 - 단어 뒤집기PS/boj 2020. 9. 13. 19:12
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Stack; public class boj_9093 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuffer sb = new StringBuffer(); int T = Integer.parseInt(br.readLine()); for (int i = 0; i < T; i++) { String str = b..
-
boj)10828 - 스택구현PS/boj 2020. 9. 13. 19:10
import java.io.*; public class boj_10828 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(br.readLine()); stack s = new stack(N); for (int i = 0; i < N; i++) { String str = br.readLine(); switch (str) { case "push" : s.push(Integer.parseInt(str.split(" ")[1])); case "pop" : s.pop(); ca..
-
boj)2644 - 촌수계산PS/boj 2020. 9. 5. 16:40
import java.io.*; import java.util.*; public class Main { static int N, M, person1, person2, x, y; static LinkedList[] nodeList; static boolean[] visited; static boolean check; static class Node { int index; int distance; public Node(int index, int distance) { this.index = index; this.distance = distance; } } public static void bfs(int start, int end) { Queue q = new LinkedList(); q.offer(new No..
-
boj)7576 - 토마토PS/boj 2020. 9. 5. 14:30
import java.io.*; import java.util.*; public class Main { static int N, M; static int[][] graph; static int[] dx = {-1, 1, 0, 0}; static int[] dy = {0, 0, -1, 1}; // x,y 좌표가 함께 움직야하고, 날짜를 세야하는데 그걸 클래스 안에 넣었음 static class Dot { int x; int y; int day; public Dot(int x, int y, int day) { this.x = x; this.y = y; this.day = day; } } public static void main(String[] args) throws IOException { input();..
-
boj)2178 - 미로 탐색PS/boj 2020. 9. 3. 18:20
import java.io.*; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; class Node { int index; int distance; public Node(int index, int distance) { this.index = index; this.distance = distance; } public int getIndex() { return index; } public int getDistance() { return distance; } } public class Main { static int n, m, nx, ny; static int[][] graph = new int[101]..
-
boj)1012 - 유기농 배추PS/boj 2020. 9. 3. 17:00
import java.io.*; import java.util.StringTokenizer; public class Main { static int t, m, n, k, x, y, ans; static int[][] graph = new int[50][50]; public static boolean dfs(int x, int y) { if (x = m || y = n) { return false; } if (graph[x][y] == 1) { graph[x][y] = 0; dfs(x - 1, y); dfs(x + 1, y); dfs(x, y - 1); dfs(x, y + 1); return true; } return false; } public static void m..