Skip to content

Instantly share code, notes, and snippets.

@luccasiau
Created April 6, 2015 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luccasiau/efe113996bf7683ed526 to your computer and use it in GitHub Desktop.
Save luccasiau/efe113996bf7683ed526 to your computer and use it in GitHub Desktop.
//
// majority.cpp
// programas2
//
// Created by Lucca Siaudzionis on 27/03/13.
// Copyright (c) 2013 Luccasiau. All rights reserved.
//
#include <cstdio>
#define MAXN 3000005
int myv[MAXN];
int main(){
int n;
scanf("%d",&n);
for(int i = 1;i<=n;i++) scanf("%d",&myv[i]);
int index = 1;
int count = 1;
for(int i = 2;i<=n;i++){
if(myv[i] == myv[index]) count++;
else count--;
if(!count){
index = i;
count = 1;
}
}
printf("%d\n",myv[index]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment