Skip to content

Instantly share code, notes, and snippets.

@peter279k
Created December 22, 2015 02:11
Show Gist options
  • Save peter279k/56c41c539a5c98ccbda7 to your computer and use it in GitHub Desktop.
Save peter279k/56c41c539a5c98ccbda7 to your computer and use it in GitHub Desktop.
import java.util.*;
public class main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int numbers = input.nextInt();
String str2 = input.nextLine();
ArrayList<String> lists = new ArrayList<String>();
String result = "";
while(input.hasNext()) {
String str = input.nextLine();
lists.add(str);
}
ArrayList<String> list = new ArrayList<String>();
for(int i=1;i<lists.size();i++) {
if(lists.get(i).equals("")) {
Collections.sort(list);
int count = 0;
for(int j=0;j<list.size();j++) {
//System.out.println(list.get(j));
if(j != list.size()-1) {
if(!list.get(j).equals(list.get(j+1))) {
count += 1;
float res = (float)count/(float)(list.size());
result = list.get(j) + " " + "%.4f" + "\r\n";
System.out.printf(result, res * 100);
result = "";
count = 0;
}
else {
count += 1;
}
}
else {
count = 1;
float res = (float)count/(float)(list.size());
result = list.get(j) + " " + "%.4f" + "\r\n";
System.out.printf(result, res * 100);
result = "";
}
}
if(i != lists.size()-1)
System.out.println();
list = new ArrayList<String>();
}
else {
list.add(lists.get(i));
}
if(i == lists.size()-1) {
Collections.sort(list);
int count = 0;
for(int j=0;j<list.size();j++) {
//System.out.println(list.get(j));
if(j != list.size()-1) {
if(!list.get(j).equals(list.get(j+1))) {
count += 1;
float res = (float)count/(float)(list.size());
result = list.get(j) + " " + "%.4f" + "\r\n";
System.out.printf(result, res * 100);
result = "";
count = 0;
}
else {
count += 1;
}
}
else {
count += 1;
float res = (float)count/(float)(list.size());
result = list.get(j) + " " + "%.4f" + "\r\n";
System.out.printf(result, res * 100);
result = "";
}
}
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment