设为首页 加入收藏

TOP

HDU 1029 Ignatius and the Princess IV
2014-11-23 22:53:54 来源: 作者: 【 】 浏览:3
Tags:HDU 1029 Ignatius and the Princess

给N个数字, N为奇数, 输出出现次数大于 N / 2 的数 1 #include
2 #include
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

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU 1217 Arbitrage 下一篇空对象模式---函数需要返回一个无..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: