給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