-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDCE207.java
More file actions
56 lines (46 loc) · 1.61 KB
/
DCE207.java
File metadata and controls
56 lines (46 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.*;
import java.io.*;
class DCE207 {
static int p[];
static BufferedReader r;
static int i,cntr=1,index,index2,max,max2;
static String a;
public static void main(String args[]){
//Scanner sc=new Scanner(System.in);
int t=0;
r=new BufferedReader(new InputStreamReader(System.in));
try{t=Integer.parseInt(r.readLine());}catch(Exception e){}
for(;t>0;t--,cntr++){
//int max_occur=0;
max=0;index=0;
//int cnt=0;
try{
a=r.readLine();}catch(Exception e){}
p=new int[30];
for(i=0;i<a.length();i++){
if(a.charAt(i)==' ')continue;
p[(int)(a.charAt(i))-(int)'a']++;
if(p[(int)(a.charAt(i))-(int)'a']>max){max=p[(int)(a.charAt(i))-(int)'a'];index=(int)a.charAt(i)-(int)'a';}
}
StringTokenizer st=new StringTokenizer(a);
System.out.println("Case #"+cntr+":");
while(st.hasMoreTokens()){
String q=st.nextToken();
max2=0;
p=new int[30];
index2=0;
for(i=0;i<q.length();i++){
p[(int)(q.charAt(i))-(int)'a']++;
if(p[(int)(q.charAt(i))-(int)'a']>max2){max2=p[(int)(q.charAt(i))-(int)'a'];index2=(int)q.charAt(i)-(int)'a';}
}
int v=0;
for(i=0;i<26;i++){
if(p[i]==max2)v++;
}
if(v>1)continue;
//System.out.println(index2);
if(index2==index){System.out.println(q);}
}
}
}
}