Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int comparator(int audience[][2],int index1, int index2) {
  6.     //Write your solution code below this line
  7.     int ecode1, ecode2, retorno, i;
  8.     ecode1 = 1;
  9.     for(i= 0; i < audience[index1][1]; i++)
  10.     {
  11.         ecode1 = ecode1*audience[index1][0];
  12.         ecode1 = ecode1%100;
  13.     }
  14.  
  15.     ecode2 = 1;
  16.     for(i= 0; i < audience[index2][1]; i++)
  17.     {
  18.         ecode2 = ecode2*audience[index2][0];
  19.         ecode2 = ecode2%100;
  20.     }
  21.     ecode2 = ecode2%100;
  22.  
  23.     if(ecode1==ecode2)
  24.         retorno = 0;
  25.     else if(ecode1 > ecode2)
  26.         retorno = -1;
  27.     else if(ecode1 < ecode2)
  28.         retorno = 1;
  29.  
  30.     return retorno;
  31. }
  32. int main () {
  33.  
  34.     int audience[10][2] = {{6,13}, {5,3}, {43,2}, {3,8}, {7,23}, {5,3}, {9,92}, {5,3}, {11,26}, {4,23}};
  35.     int i, j, min, aux1, aux2, j_index, i_index, N = 10;
  36.  
  37.     for(i = 0,j=1; i < N,j < (N-1); i++,j++)
  38.     {
  39.         if(comparator(audience,i,j) == -1)
  40.         {
  41.             i_index = i;
  42.             break;
  43.         }
  44.     }
  45.  
  46.     for(i = N-1,j=N-2; j >= 0; i--,j--)
  47.     {
  48.         if(comparator(audience,i,j) == 1)
  49.         {
  50.             j_index = i;
  51.             break;
  52.         }
  53.     }
  54.     for(i = (i_index + 1); i < (j_index -2);i++)
  55.     {
  56.         min = i;
  57.         for(j = i+1; j < (j_index -1);j++)
  58.         {
  59.             if(comparator(audience,i,j) == 1)// se aud[j] > aud[i] == 1
  60.                 min = i;
  61.             if (comparator(audience,i,j) == -1)//se  i > j
  62.                 min = j;
  63.             else
  64.                 min = j; //se i = j ==0
  65.  
  66.             if(min != i)
  67.             {
  68.                 aux1 = audience[i][0];
  69.                 aux2 = audience[i][1];
  70.  
  71.                 audience[i][0] = audience[min][0];
  72.                 audience[i][1] = audience[min][1];
  73.  
  74.                 audience[min][0] = aux1;
  75.                 audience[min][1] = aux2;
  76.             }
  77.             }
  78.     }
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement