Guest User

Untitled

a guest
Jul 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.57 KB | None | 0 0
  1. //package acmp178;
  2. import java.io.*;
  3. import java.util.Arrays;
  4. public class Main {
  5.     //static StreamTokenizer st;
  6.     //public static int get() throws IOException {
  7.    //     st.nextToken();
  8.    //     return (int) st.nval;
  9.   //  }
  10.     public static void main(String[] args) throws IOException {
  11.         BufferedReader br = new BufferedReader (new FileReader("input.txt"));
  12.         BufferedWriter bw = new BufferedWriter (new FileWriter("output.txt"));
  13.         //st = new StreamTokenizer(new FileReader("input.txt"));
  14.  
  15.         int n = Integer.valueOf(br.readLine());
  16.         //int n = get();
  17.         String[]a = br.readLine().split(" ");
  18.         int[] ar = new int[n];
  19.         for(int i=0; i<n;i++){
  20.             ar[i]=Integer.valueOf(a[i]);
  21.            // ar[i] = get();
  22.         }
  23.         //int[] ar1 = Arrays.copyOf(ar, n);
  24.         int[] ar1 = new int[n];
  25.         for(int i=0; i<n;i++){
  26.             ar1[i]=ar[i];
  27.         }
  28.         Arrays.sort(ar);
  29.         int max = 0;
  30.         int max1 = 0;
  31.         int numb = 0;
  32.         int numb1 = 0;
  33.         int cnt = 0;
  34.  
  35.         for(int i=0; i<n;i++){
  36.             numb1 = ar[i];
  37.             max1 = 1;
  38.             for(int j=i; j<n-1;j++){
  39.                 if(ar[j+1]==ar[i]){
  40.                     max1++;
  41.                 } else {
  42.                     i = j;
  43.                     break;
  44.                 }
  45.             }
  46.             if(max1>max){
  47.                 max = max1;
  48.                 numb = numb1;
  49.             } else if (max1==max){
  50.                 if(numb1<numb){
  51.                     max = max1;
  52.                     numb = numb1;
  53.                 }
  54.             }
  55.         }
  56.       /* //System.out.println(max);
  57.         int[]ar2 = new int[n];
  58.         for(int i=0; i<n;i++){
  59.             if(ar1[i]!=numb){
  60.                 //System.out.println(ar1[i]);
  61.                 ar2[cnt]=ar1[i];
  62.                 bw.write(ar2[cnt]+" ");
  63.                 cnt++;
  64.                
  65.             }
  66.         }
  67.         //System.out.println(cnt);
  68.         for(int i=cnt; i<n;i++){
  69.             ar2[i] = numb;
  70.             if(i!=n-1){
  71.                 bw.write(ar2[i]+" ");
  72.             } else {
  73.                 bw.write(ar2[i]+"");
  74.             }
  75.            
  76.            System.out.print(ar2[i]);
  77.         }*/
  78.         for(int i=0; i<n;i++){
  79.             if(ar1[i]!=numb){
  80.                 bw.write(ar1[i]+" ");
  81.             }
  82.         }
  83.         for(int i=0; i<max;i++){
  84.             if(i!=max-1){
  85.                 bw.write(numb+" ");
  86.             } else {
  87.                 bw.write(numb+"");
  88.             }
  89.  
  90.         }
  91.         bw.close();
  92.     }
  93.  
  94. }
Add Comment
Please, Sign In to add comment