import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer("");
String m = "";
LinkedList<String> list=new LinkedList<String>();
int cases=1;
while((m=br.readLine())!=null){
while(!m.equals("9")){
list.add(m);
m=br.readLine();
}
String[]arr=new String[list.size()];
for(int i=0;i<arr.length;i++){
arr[i]=list.remove();
}
boolean pre=false;
for(int i=0;i<arr.length-1;i++){
for(int j=i+1;j<arr.length;j++){
if(isPrefix(arr[i],arr[j])){
pre=true;
break;
}
}
if(pre)
break;
}
if(pre){
sb.append("Set ").append(cases).append(" is not immediately decodable\n");
}
else{
sb.append("Set ").append(cases).append(" is immediately decodable\n");
}
cases++;
}
System.out.print(sb);
}
static boolean isPrefix(String x,String y){
for(int i=0,j=0;i<Math.min(x.length(), y.length());i++){
if(x.charAt(i)!=y.charAt(i)){
return false;
}
}
return true;
}
}
No comments:
Post a Comment