import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
StringBuffer sb = new StringBuffer("");
String m="";
boolean [] notprimes=sievePrime(2000);
int cases=Integer.parseInt(br.readLine());
for(int i=0;i<cases;i++) {
int[] arr=new int[128];
m=br.readLine();
for(int j=0;j<m.length();j++){
arr[m.charAt(j)]++;
}
boolean flag=true;
sb.append("Case ").append((i+1)).append(": ");
for(int j=0;j<arr.length;j++){
if(!notprimes[arr[j]]){
sb.append((char)j);
flag=false;
}
}
if(flag)
sb.append("empty");
sb.append("\n");
}
System.out.print(sb);
}
static boolean[] sievePrime(int x) {
boolean[] notPrime = new boolean[x + 1];
notPrime[0] = true;
notPrime[1] = true;
for (int i = 2; i * i < x + 1; i++) {
if (!notPrime[i]) {
for (int j = i; i * j < x + 1; j++) {
notPrime[i * j] = true;
}
}
}
return notPrime;
}
}
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
StringBuffer sb = new StringBuffer("");
String m="";
boolean [] notprimes=sievePrime(2000);
int cases=Integer.parseInt(br.readLine());
for(int i=0;i<cases;i++) {
int[] arr=new int[128];
m=br.readLine();
for(int j=0;j<m.length();j++){
arr[m.charAt(j)]++;
}
boolean flag=true;
sb.append("Case ").append((i+1)).append(": ");
for(int j=0;j<arr.length;j++){
if(!notprimes[arr[j]]){
sb.append((char)j);
flag=false;
}
}
if(flag)
sb.append("empty");
sb.append("\n");
}
System.out.print(sb);
}
static boolean[] sievePrime(int x) {
boolean[] notPrime = new boolean[x + 1];
notPrime[0] = true;
notPrime[1] = true;
for (int i = 2; i * i < x + 1; i++) {
if (!notPrime[i]) {
for (int j = i; i * j < x + 1; j++) {
notPrime[i * j] = true;
}
}
}
return notPrime;
}
}
No comments:
Post a Comment