HDU 1029 Ignatius and the Princess IV给N个数字, N为奇数, 输出出现次数大于 N / 2 的数
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int main()
5 {
6 int ans, num, count, n;
7 while (scanf("%d", &n) != EOF)
8 {
9 count = 0;
10 for (int i=1; i<=n; i++)
11 {
12 scanf("%d", &ans);
13 if (count == 0)
14 {
15 num = ans;
16 count ++;
17 }
18 else if (ans == num)count++;
19 else count--;
20 }
21 printf("%d\n", num);
22 }
23 }
24