Created
April 6, 2015 02:45
-
-
Save luccasiau/efe113996bf7683ed526 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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