1 #include <iostream>
2 using namespace std;
3
4 #include <stdlib.h>
5 #include <sys/types.h>
6
7 int Count(int * a, int n)
8 {
9 int count = 0;
10 int candidate = a[0];
11 while (n) {
12 if (count == 0) {
13 candidate = a[n-1];
14 ++count;
15 } else if (candidate == a[n - 1]) {
16 ++count;
17 } else {
18 --count;
19 }
20 --n;
21 }
22 return candidate;
23 }
24
25 int main()
26 {
27 const int n = 7;
28 int a[n] = {1, 1, 1, 1, 2, 3, 4};
29 cout << Count(a, n) << endl;
30
31 return 0;
32 }
转载于:https://www.cnblogs.com/tzhangofseu/archive/2011/10/21/2220332.html