题解 | #频繁元素#

频繁元素

https://ac.nowcoder.com/acm/problem/22229

#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[100];

for( int i = 0 ; i < n ; i ++ )   
{
    cin >> a[i];
}

int s = 0 , ans = 0;
for( int i = 0 ; i < n ; i ++ )
{
    int cnt = 0;
    for( int j = 0 ; j < n ; j ++ ) 
    {
        if(a[i] == a[j]) cnt ++;
    }
    if(s < cnt)
    {
        s = cnt;
        ans = a[i];
    }
}
cout << ans;

}

全部评论

相关推荐

06-26 15:33
青岛工学院 Java
积极的秋田犬要冲国企:他现在邀请我明天面试
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务