Submit solution
Points:
1.00 (partial)
Time limit:
1.0s
Memory limit:
256M
Input:
stdin
Output:
stdout
Author:
Problem source:
Problem type
Allowed languages
C, C#, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
Cho mảng số nguyên A[] gồm N phần tử, hãy tìm giá trị có số lần xuất hiện nhiều nhất trong mảng, nếu có nhiều giá trị có cùng số lần xuất hiện thì lấy số có giá trị nhỏ nhất
Tham khảo thêm lý thuyết mảng đánh dấu : [C++]. Mảng Đánh Dấu
Đầu vào
Dòng đầu tiên là số nguyên dương N
Dòng thứ 2 gồm N số nguyên viết cách nhau một vài khoảng trắng
Giới hạn
1<=N<=1000
0<=A[i]<=10^6
Đầu ra
In ra giá trị có số lần xuất hiện nhiều nhất kèm theo tần suất của nó
Ví dụ :
Input 01
5
9 4 0 4 5
Output 01
4 2
Input 02
5
1 2 3 4 5
Output 02
1 1
Comments
include <bits/stdc++.h>
using namespace std; using ll = long long;
int main(){ iosbase::syncwithstdio(false); cin.tie(nullptr); freopen("vao.inp","r",stdin); freopen("ra.out","w",stdout); int n; cin >> n; map<int,int> mp; pair<int,int> v (INTMIN,INT_MIN); while (n--) { int x; cin >> x; mp[x]++; } for (auto x : mp) { if (x.second > v.second) { v.second = x.second; v.first = x.first; } else if (x.second == v.second) if (v.first > x.first) { v.first = x.first; } } cout << v.first << " " << v.second; return 0; }
include<stdio.h>
int main(){ int a[1000], b[1000]={0}, max=-1000000; int n; scanf("%d", &n); for(int i =0; i<n; i++) scanf("%d", &a[i]); for(int i=0; i<n; i++){ b[a[i]]++; if(a[i]>max) max = a[i]; } int m=0, c; for(int i=0; i<=max; i++){ if(b[i]){ if(b[i]>m){ m=b[i]; c=i; } } } printf("%d %d", c, m);
}
include <bits/stdc++.h>
using namespace std; int a[1000001]; int dd[1000001]; int main() { int n;cin>>n; int m=0; for(int i=0;i<n;i++){ cin>>a[i]; dd[a[i]]++; m=max(dd[a[i]],m); } for(int i=0;i<1000001;i++){ if(dd[i]==m){ cout<<i<<" "<<m; break; } } }
using namespace std; long long m[1000001] = {0}; long long n; int main(){ cin >> n; long long a[n]; for(int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for(int i = 0; i < n; i++){ m[a[i]] ++; } int res = 0; for(int i = 0; i < n; i++){ if(res < m[a[i]]) res = m[a[i]]; } for(int i = 0; i < n; i++){ if(res == m[a[i]]){ cout << a[i] << ' ' << m[a[i]]; break; } } return 0; }
include<iostream>
include<algorithm>
using namespace std;
long long m[1000001] = {0}; long long n; int main(){ cin >> n; long long a[n]; for(int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for(int i = 0; i < n; i++){ m[a[i]] ++; } int res = 0; for(int i = 0; i < n; i++){ if(res < m[a[i]]) res = m[a[i]]; } for(int i = 0; i < n; i++){ if(res == m[a[i]]){ cout << a[i] << ' ' << m[a[i]]; break; } } return 0; }
FULL AC
This comment is hidden due to too much negative feedback. Show it anyway.
đây ko phải môn đạo lý
đang nói gì vậy
This comment is hidden due to too much negative feedback. Show it anyway.