Advertisement
Guest User

QuestaoFDP

a guest
Nov 22nd, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     //n = number of pirates
  7.     int n , aux, in, result=0;
  8.     scanf("%d %d", &n, &in);
  9.     aux =0; //1ª posicao sera usada como indice mais p frente
  10.     int ar[n];
  11.     int comp[n];
  12.     ar[0] = in;
  13.  
  14.         //preenchendo o array com as desvantagens
  15.         for(int j = 1; j < n; j++){
  16.             scanf("%d", &ar[j]);
  17.         }
  18.  
  19.         //comparando e salvando o de maior # de comparações
  20.         for(int i = 1; i < n; i++){
  21.         comp[aux]++;
  22.         comp[i]++;
  23.        
  24.         if((ar[aux] > ar[i]) || (i == n-1)){
  25.             if(comp[aux] > comp[result]){
  26.                 result = aux;
  27.             }
  28.                 aux = i;
  29.         }  
  30.  
  31.     }
  32.     printf("%d \n", result+1); 
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement