Guest User

Untitled

a guest
Sep 15th, 2019
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.  
  9.     int repeatedNums[10]{0};
  10.     int vSize=0;
  11.     cin>>vSize;
  12.  
  13.     vector <int> myVector;
  14.  
  15.     for(int a=0; a<vSize; a++){
  16.         int input=0;
  17.         cin>>input;
  18.  
  19.         repeatedNums[input]+=1;
  20.         myVector.push_back(input);
  21.     }
  22.  
  23.     int maximum=-1;
  24.     vector<int>concatenated;
  25.     int counter=1;
  26.     bool validate=false;
  27.  
  28.     for(int a=0; a<10 ;a++ ){
  29.         if(repeatedNums[a]>maximum){
  30.             maximum=repeatedNums[a];
  31.             counter=a;
  32.             validate=false;
  33.         }
  34.         if(repeatedNums[a]==maximum && counter!=a){
  35.             if(validate==false){
  36.                 concatenated.push_back(counter);
  37.             }
  38.  
  39.             concatenated.push_back(a);
  40.             validate=true;
  41.         }
  42.  
  43.     }
  44.     if(validate==false){
  45.         cout<<counter;
  46.     } else {
  47.         for(int& a : concatenated){
  48.         cout<< a << " ";
  49.         }
  50.     }
  51.  
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment