diff --git "a/BOJ/Java/src/S4/Boj_4821_\355\216\230\354\235\264\354\247\200\354\204\270\352\270\260.java" "b/BOJ/Java/src/S4/Boj_4821_\355\216\230\354\235\264\354\247\200\354\204\270\352\270\260.java" new file mode 100644 index 00000000..2af7e5a3 --- /dev/null +++ "b/BOJ/Java/src/S4/Boj_4821_\355\216\230\354\235\264\354\247\200\354\204\270\352\270\260.java" @@ -0,0 +1,49 @@ +package S4; + +import java.io.*; +import java.util.StringTokenizer; + +public class Boj_4821_페이지세기 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + + int max; + + while ((max = Integer.parseInt(br.readLine())) != 0) { + StringTokenizer st = new StringTokenizer(br.readLine(), ","); + boolean[] used = new boolean[max + 1]; + + while (st.hasMoreTokens()) { + String s = st.nextToken(); + + if (s.contains("-")) { + StringTokenizer st2 = new StringTokenizer(s, "-"); + int start = Integer.parseInt(st2.nextToken()); + int end = Integer.parseInt(st2.nextToken()); + + for (int i = start; i <= end && i <= max; i++) { + used[i] = true; + } + } else { + int page = Integer.parseInt(s); + if (0 < page && page <= max) { + used[Integer.parseInt(s)] = true; + } + } + } + + int cnt = 0; + + for (boolean use : used) { + if (use) cnt++; + } + + sb.append(cnt).append('\n'); + } + + bw.write(sb.toString()); + bw.flush(); + } +}