Advertisement
Guest User

Untitled

a guest
May 20th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Ege8 {
  3.     public static void main(String[] args) {
  4.         Scanner sc = new Scanner(System.in);
  5.         int N = sc.nextInt();
  6.         String[] title = new String[12];
  7.         int[] count = new int[12];
  8.         String s;
  9.         int t=0;
  10.         int number =-1;
  11.         for(int i = 0; i <= N; i++){
  12.             s = sc.nextLine();
  13.             int j = 0;
  14.             while(j < number && s != title[j] ){
  15.                 j++;
  16.             }
  17.             if(j < number){
  18.                 count[j] = count[j] + 1;
  19.             }
  20.             else
  21.             title[j] = s;
  22.             count[j] = 1;
  23.             number ++;
  24.         }
  25.         for(int i = number; i >= 2; i--){
  26.             for(int j = 2; count[j-1] > count[j]; j++){
  27.                 t = count[j];
  28.                 count[j] = count[j-1];
  29.                 count[j-1] = t;
  30.                 s = title[j];
  31.                 title[j] = title[j-1];
  32.                 title[j-1] = s;
  33.             }}
  34.  
  35.         if (number >= 3){
  36.             number = 3;}
  37.  
  38.         for(int i = 1 ; i <= number; i++){
  39.             System.out.println(title[i] + " " + count[i]);
  40.         }
  41.  
  42.     }
  43.  
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement