HDU-1029-Ignatius and the Princess IV

来源:互联网 发布:数据库安全防护总结 编辑:程序博客网 时间:2024/06/03 14:59

题意
给出一个N(奇数)个数的序列求 序列中某个出现频率超过(N+1)/2的数
解法
水题

    #include <iostream>    #include <cstdio>    #include <cstdlib>    using namespace std;    int main()    {        int n;        while(cin>>n)        {            int temp,t=0,ans;            while(n--)            {                scanf("%d",&temp);                if(t==0)                {                    ans=temp;                    t++;                }                else                {                    if(ans==temp)                    {                        t++;                    }                    else                    {                        t--;                    }                }            }             cout<<ans<<endl;        }        return 0;    }
0 0