• 문제 링크
23568번: Find the House
Your program is to read from standard input. The input starts with a line containing an integer $n$ ($1 ≤ n ≤ 10,000$), where $n$ is the number of triples in the list. In the following $n$ lines, $n$ triples are given where each triple is represented a
www.acmicpc.net
• 풀이 과정
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class Main {
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 n = Integer.parseInt(br.readLine());
Map<Integer, Pair> map = new HashMap<>();
for (int i = 0; i < n; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
map.put(Integer.parseInt(st.nextToken()), new Pair(st.nextToken(), Integer.parseInt(st.nextToken())));
}
int cur = Integer.parseInt(br.readLine());
while (n-- > 0) {
Pair pair = map.get(cur);
if (pair.dir.equals("L")) cur -= pair.dist;
else cur += pair.dist;
}
bw.write(String.valueOf(cur));
bw.flush();
}
private static class Pair {
String dir;
int dist;
public Pair(String dir, int dist) {
this.dir = dir;
this.dist = dist;
}
}
}'Problem Solving > Baekjoon' 카테고리의 다른 글
| [백준] 17199 Milk Factory - Graph Theory / Java (0) | 2023.07.03 |
|---|---|
| [백준] 5966 Cow Cotillion - Data Structure / Java (0) | 2023.07.02 |
| [백준] 10654 Cow Jog - Data Structure / Java (0) | 2023.06.30 |
| [백준] 10657 Cow Jog - Data Structure / Java (0) | 2023.06.30 |
| [백준] 10527 Judging Troubles - Data Structure / Java (0) | 2023.06.29 |
댓글