Skip to content

Commit

Permalink
CT_299
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade-Good committed Nov 4, 2024
1 parent dd63967 commit 082a990
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions BOJ/Java/src/S4/Boj_4821_페이지세기.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 082a990

Please sign in to comment.