SHARE
TWEET

Untitled

a guest Aug 20th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int n, m, v[101][101];
  7.  
  8.     cin >> n >> m;
  9.     for (int i = 1; i <= n; ++i)
  10.         for (int j = 1; j <= m; ++j)
  11.             cin >> v[i][j];
  12.  
  13.     int fr[1000001] = {0}, maxfr = -1;
  14.     for (int i = 1; i <= n; ++i)
  15.     {
  16.         for (int j = 1; j <= m; ++j)
  17.         {
  18.             fr[v[i][j]]++;
  19.             if (fr[v[i][j]] > maxfr)
  20.                 maxfr = fr[v[i][j]];
  21.         }
  22.     }
  23.  
  24.     int w[1000001] = {0}, k = 0;
  25.     for (int i = 1; i <= n; ++i)
  26.     {
  27.         for (int j = 1; j <= m; ++j)
  28.         {
  29.             if (fr[v[i][j]] == maxfr)
  30.             {
  31.                 w[++k] = v[i][j];
  32.             }
  33.         }
  34.     }
  35.  
  36.     int dontstop = 1;
  37.     while (dontstop)
  38.     {
  39.         int stop = 1;
  40.         for (int i = 1; i < k; ++i)
  41.         {
  42.             if (w[i] > w[i + 1])
  43.             {
  44.                 int aux = w[i];
  45.                 w[i] = w[i + 1];
  46.                 w[i + 1] = aux;
  47.  
  48.                 stop = 0;
  49.             }
  50.         }
  51.  
  52.         if (stop == 1)
  53.             dontstop = 0;
  54.     }
  55.  
  56.     for (int i = 1; i < k; ++i)
  57.         if (w[i] != w[i + 1])
  58.             cout << w[i] << " ";
  59.     cout << w[k];
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top