Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Ege8 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int N = sc.nextInt();
- String[] title = new String[12];
- int[] count = new int[12];
- String s;
- int t=0;
- int number =-1;
- for(int i = 0; i <= N; i++){
- s = sc.nextLine();
- int j = 0;
- while(j < number && s != title[j] ){
- j++;
- }
- if(j < number){
- count[j] = count[j] + 1;
- }
- else
- title[j] = s;
- count[j] = 1;
- number ++;
- }
- for(int i = number; i >= 2; i--){
- for(int j = 2; count[j-1] > count[j]; j++){
- t = count[j];
- count[j] = count[j-1];
- count[j-1] = t;
- s = title[j];
- title[j] = title[j-1];
- title[j-1] = s;
- }}
- if (number >= 3){
- number = 3;}
- for(int i = 1 ; i <= number; i++){
- System.out.println(title[i] + " " + count[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement