Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4.  
  5. class hfak{
  6. public static void main(String[] args){
  7. Scanner sc=new Scanner(System.in);
  8. List<String> output=new ArrayList<String>();
  9.  
  10. while(sc.hasNext()){
  11. int a=sc.nextInt();
  12. if(a==0)
  13. break;
  14. List<String> color=new ArrayList<String>();
  15. List<Integer> count=new ArrayList<Integer>();
  16. String c=sc.nextLine();
  17. String modelcolor=c;
  18. int modelcount=1;
  19. while(--a>=0){
  20. String x=sc.nextLine();
  21. if (color.contains(x)){
  22. count.set(color.indexOf(x),count.get(color.indexOf(x))+1);
  23. if(count.get(color.indexOf(x))>modelcount){
  24. modelcolor=x;
  25. modelcount=count.get(color.indexOf(x));
  26. }
  27. }
  28. else{
  29. color.add(x);
  30. count.add(1);
  31. }
  32. }
  33. output.add(modelcolor);
  34.  
  35. }
  36. for (int i=0;i<output.size();i++){
  37.  
  38. System.out.println(output.get(i));
  39. }
  40.  
  41. }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement