import java.util.*;
import java.lang.*;
import java.io.*;
// The main method must be in a class named "Main".
class Main {
public static void main(String[] args) {
// 1번 예시
String message = "here is muzi here is a secret message";
int[][] spoiler_ranges = {{0, 3},{23,28}};
// 2번 예시
//String message = "my phone number is 01012345678 and may i have your phone number";
//int[][] spoiler_ranges = {{5,5},{25,28},{34,40},{53,59}};
String[] words = message.split(" ");
char[] chMsg = message.toCharArray();
boolean[] spoArr = new boolean[chMsg.length];
for(int i = 0; i < spoiler_ranges.length; i++) {
for (int j = spoiler_ranges[i][0]; j <= spoiler_ranges[i][1]; j++) {
spoArr[j] = true;
}
}
//for(int i = 0; i < chMsg.length; i++) {
// System.out.print("*** ["+(i+1)+"] ***\n[CharMessage:"+chMsg[i]+" / SpoArr:"+spoArr[i]+"]\n");
//}
int wordIdx = 0;
boolean isSpoiler = false;
HashSet<String> spoiler = new HashSet<>();
HashSet<String> nonSpoiler = new HashSet<>();
for(int i = 0; i < chMsg.length; i++){
char c = chMsg[i];
if(c != ' ' && i != chMsg.length - 1){
if(spoArr[i]){
isSpoiler = true;
}
}else if(c == ' ' || i == chMsg.length - 1){
String word = words[wordIdx];
if(!isSpoiler){
nonSpoiler.add(word);
}else{
spoiler.add(word);
}
wordIdx++;
isSpoiler = false;
}
}
for(String ns : nonSpoiler){
spoiler.remove(ns);
}
System.out.print(spoiler.size());
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: