Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- int comparator(int audience[][2],int index1, int index2) {
- //Write your solution code below this line
- int ecode1, ecode2, retorno, i;
- ecode1 = 1;
- for(i= 0; i < audience[index1][1]; i++)
- {
- ecode1 = ecode1*audience[index1][0];
- ecode1 = ecode1%100;
- }
- ecode2 = 1;
- for(i= 0; i < audience[index2][1]; i++)
- {
- ecode2 = ecode2*audience[index2][0];
- ecode2 = ecode2%100;
- }
- ecode2 = ecode2%100;
- if(ecode1==ecode2)
- retorno = 0;
- else if(ecode1 > ecode2)
- retorno = -1;
- else if(ecode1 < ecode2)
- retorno = 1;
- return retorno;
- }
- int main () {
- int audience[10][2] = {{6,13}, {5,3}, {43,2}, {3,8}, {7,23}, {5,3}, {9,92}, {5,3}, {11,26}, {4,23}};
- int i, j, min, aux1, aux2, j_index, i_index, N = 10;
- for(i = 0,j=1; i < N,j < (N-1); i++,j++)
- {
- if(comparator(audience,i,j) == -1)
- {
- i_index = i;
- break;
- }
- }
- for(i = N-1,j=N-2; j >= 0; i--,j--)
- {
- if(comparator(audience,i,j) == 1)
- {
- j_index = i;
- break;
- }
- }
- for(i = (i_index + 1); i < (j_index -2);i++)
- {
- min = i;
- for(j = i+1; j < (j_index -1);j++)
- {
- if(comparator(audience,i,j) == 1)// se aud[j] > aud[i] == 1
- min = i;
- if (comparator(audience,i,j) == -1)//se i > j
- min = j;
- else
- min = j; //se i = j ==0
- if(min != i)
- {
- aux1 = audience[i][0];
- aux2 = audience[i][1];
- audience[i][0] = audience[min][0];
- audience[i][1] = audience[min][1];
- audience[min][0] = aux1;
- audience[min][1] = aux2;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement