Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.io.PrintWriter;
  5. import java.util.ArrayList;
  6. import java.util.Collections;
  7. import java.util.Comparator;
  8. import java.util.List;
  9.  
  10. class TheNameList {
  11.     public static void main(String[] args)throws IOException {
  12.         try{
  13.         BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
  14.         PrintWriter p = new PrintWriter(System.out, true);
  15.         int t = Integer.parseInt(b.readLine());
  16.         if(t>=1 && t<=100000){
  17.             List<String> n = new ArrayList<String>(t);
  18.             for(int i= 0;i<t; ){
  19.                 String s = b.readLine().toLowerCase();
  20.                 int len = s.length();
  21.                 if(len>30 && len<1){
  22.                     break;
  23.                 }else {n.add(s);i++;}
  24.             }
  25.             Collections.sort(n, new Comparator<String>() {
  26.                 @Override
  27.                 public int compare(String o1, String o2) {              
  28.                     return o1.compareToIgnoreCase(o2);
  29.                 }
  30.             });//sorting completed...
  31.            
  32.             for(int j=0; j<t;j++){
  33.                  int c=1;
  34.                 int k=j;
  35.                 for(int i=j+1;i<t;i++){
  36.                     if(n.get(j).equals(n.get(i))){c++;continue;}
  37.                     else {j=i-1; break;}
  38.                 }
  39.                 p.println(n.get(k)+" "+c);
  40.             }
  41.         }
  42.         }catch(Exception ex){
  43.            
  44.         }
  45.     }
  46.    
  47.    
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement