zoj 3869

来源:互联网 发布:yy协议号软件 编辑:程序博客网 时间:2024/05/12 05:46

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3869

题意:找出出现次数最多的数,如果次数最多的数有多个直接输出nobody

背景:昨晚断电前开始敲这个水题,交了却wa了一发。。。结果断电了。。然后中午过来看,居然WA了漏了break。

代码:

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define M 1009#define INF 0x3f3f3f3fint mark[M];int s[M];int main(){    int n;    scanf("%d",&n);    while(n--)    {        memset(mark,0,sizeof(mark));        int m;        scanf("%d",&m);        for(int i = 0;i < m;i++)        {            scanf("%d",&s[i]);            mark[s[i]]++;        }        int count = 0;        int ans = -1;        int ok = 0;        for(int i = 0;i <= 1000;i++)        {            if(count < mark[i])            {                count = mark[i];                ans = i;            }        }        for(int i = 0;i <= 1000;i++)        {            if(mark[i] == count && i!=ans)            {                printf("Nobody\n");                ok = 1;                break; //这都能漏!!!!!            }        }        if(!ok)            printf("%d\n",ans);    }    return 0;}


0 0
原创粉丝点击