Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. void cycleTrue(int aray[],int aSize);
  8. int digit(int [], int  );
  9. int counter(int [], int );
  10.  
  11.  
  12. main () {
  13.  
  14.     int counter44;
  15.     int arayLenght=0;
  16.     cin>>arayLenght;
  17.     int currentDigit;
  18.  
  19.     int myArray[arayLenght]{};
  20.     cycleTrue(myArray, arayLenght);
  21.     currentDigit=digit(myArray,arayLenght);
  22.     counter44=counter(myArray,arayLenght);
  23.  
  24.     if(counter44!=1){
  25.         for(int a=0;a<counter44;){
  26.             ++a;
  27.             cout<<currentDigit;
  28.             if(a==counter44){
  29.                 break;
  30.             } else {
  31.             cout<<" ";
  32.             }
  33.         }
  34.     } else {
  35.         cout<<currentDigit;
  36.     }
  37.  
  38.  
  39. return 0;
  40. }
  41.  
  42.  
  43.  
  44. void cycleTrue(int aray[], int aSize){
  45.  
  46.     for(int a=0 ; a<aSize ; a++){
  47.         int current=0;
  48.         cin>> current;
  49.         aray[a]=current;
  50.     }
  51. }
  52.  
  53. int counter(int array1[], int arrLenght1){
  54.     int possitionCounter=1;
  55.         int digitsCounter=1;
  56.  
  57.         int currentMax=0;
  58.         bool validation=false;
  59.  
  60.         for(int a=0 ; a<arrLenght1 ; a++){
  61.  
  62.  
  63.             if(array1[a]==array1[possitionCounter]){
  64.                 if(possitionCounter==arrLenght1){
  65.                     break;
  66.                 }
  67.                 digitsCounter++;
  68.  
  69.             } else if ((currentMax==0 || validation==true) && currentMax<digitsCounter){
  70.                 validation=true;
  71.                 currentMax=digitsCounter;
  72.                 digitsCounter=1;
  73.             } else {
  74.                 digitsCounter=1;
  75.             }
  76.             possitionCounter++;
  77.         }
  78.     if(currentMax!=1){
  79.  
  80.     return currentMax;
  81.  
  82.     } else {
  83.     return currentMax;
  84.     }
  85. }
  86.  
  87.  
  88. int digit(int array1[], int arrLenght1){
  89.         int possitionCounter=1;
  90.         int digitsCounter=1;
  91.         int digit=0;
  92.         int currentMax=0;
  93.         bool validation=false;
  94.  
  95.         for(int a=0 ; a<arrLenght1 ; a++){
  96.  
  97.  
  98.             if(array1[a]==array1[possitionCounter]){
  99.                 if(possitionCounter==arrLenght1){
  100.                     break;
  101.                 }
  102.                 if(currentMax>digitsCounter){
  103.                     digitsCounter++;
  104.                     if(currentMax==digitsCounter){
  105.                         digit=array1[a];
  106.                     }
  107.  
  108.                 } else  {
  109.                     digit=array1[a];
  110.                     digitsCounter++;
  111.                 }
  112.  
  113.             } else if ((currentMax==0 || validation==true) && currentMax<digitsCounter){
  114.                 validation=true;
  115.                 currentMax=digitsCounter;
  116.                 digitsCounter=1;
  117.             } else {
  118.                 digitsCounter=1;
  119.             }
  120.             possitionCounter++;
  121.         }
  122.     if(currentMax!=1){
  123.  
  124.     return digit;
  125.  
  126.     } else {
  127.     return digit=array1[arrLenght1-1];
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement