题解 | #频繁元素#

频繁元素

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

#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int nums[20], n, count = 0, max = 0, m;
    
    if(cin >> n) {
        for(int i = 0; i < n; i++) {
            cin >> nums[i];
        }
        
        for(int i = 0; i < n; i++) {
            count = 0;
            for(int j = 0; j < n; j++) {
                if(nums[i] == nums[j]) {
                    count++;
                }
                
                 if(count > max) {
                    max = count;
                    m = nums[i];
                 }
            }
        }
    }
    
    printf("%d\n", m);
    
    return 0;
}
全部评论

相关推荐

06-26 18:30
门头沟学院 Java
据说名字越长别人越关...:你问问这里面有多少是正经候选人,而不是乱打招呼的
点赞 评论 收藏
分享
asdasdasda...:19岁,不容易啊可能升个本会好点,现在学历歧视太严重了
点赞 评论 收藏
分享
05-22 09:23
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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