Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #define SPREAD_SIZE 97
  5.  
  6. struct dat {
  7.     int n;
  8.     int c;
  9. };
  10.  
  11. dat v[SPREAD_SIZE][10005];
  12.  
  13. int main(){
  14.     int n, x, i, x_hash, n_cp2;
  15.     int max_nr = -1, max_c = 0;
  16.     int last_index;
  17.    
  18.     cin>>n;
  19.     n_cp2 = n / 2;
  20.    
  21.     for(i = 0; i < SPREAD_SIZE; i++) v[i][0].n = 1;
  22.    
  23.     while(n--){
  24.         cin>>x;
  25.         x_hash = x % SPREAD_SIZE;
  26.        
  27.         last_index = 0;
  28.         for(i = 1; i <= v[x_hash][0].n; i++){
  29.             if(v[x_hash][i].n == x){
  30.                 v[x_hash][i].c ++;
  31.                 last_index = i;
  32.                 break;
  33.             }
  34.         }
  35.         if(!last_index){
  36.             last_index = v[x_hash][0].n;
  37.             v[x_hash][last_index].n = x;
  38.             v[x_hash][last_index].c = 1;
  39.             v[x_hash][0].n ++;
  40.         }
  41.        
  42.         if(v[x_hash][last_index].c > max_c){
  43.             max_c = v[x_hash][last_index].c;
  44.             max_nr = v[x_hash][last_index].n;
  45.         }
  46.        
  47.         if(max_c >= n_cp2) break;
  48.     }
  49.    
  50.     if(max_c >= n_cp2) {
  51.         cout<<"DA "<<max_nr;
  52.     }
  53.     else {
  54.         cout<<"NU";
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement