码迷,mamicode.com
首页 > 其他好文 > 详细

主元素问题

时间:2017-09-28 19:13:34      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:ring   class   string   scanf   color   name   none   ide   click   

技术分享
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<cmath>
 7 using namespace std;
 8 int n,a[1005],x,y,i;
 9 int main()
10 {
11     scanf("%d",&n);
12     for(i=1;i<=n;i++)
13     {
14         scanf("%d",&a[i]);
15         if(y==0)
16         {
17             x=a[i];
18             y++;
19         }
20         else
21         {
22             if(x==a[i]) y++;
23             else y--;
24         }
25     }
26     y=0;
27     for(i=1;i<=n;i++)
28         if(a[i]==x)
29             y++;
30     if(y>n/2) printf("%d",x);
31     else printf("NO");
32     return 0;
33 }
代码

 

主元素问题

标签:ring   class   string   scanf   color   name   none   ide   click   

原文地址:http://www.cnblogs.com/dfzg/p/7608045.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!