HDU 1029 Ignatius and the Princess IV

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 


posted on 2011-08-16 17:10 AK 阅读(1423) 评论(0)  编辑 收藏 引用 所属分类: ACM


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2011年8月>
31123456
78910111213
14151617181920
21222324252627
28293031123
45678910

导航

统计

常用链接

留言簿(1)

随笔分类

随笔档案

资源连接

搜索

最新评论

阅读排行榜

评论排行榜