Points:
100 (p)
Time limit:
1.0s
Memory limit:
256M
Input:
stdin
Output:
stdout
Cho một dãy gồm \(n\) số nguyên dương \(A_1,A_2,\ldots,A_n\)..
Yêu cầu: Hãy in ra các phần tử của mảng theo thứ tự tăng dần cùng với số lần xuất hiện của chúng, các số trùng nhau thì chỉ ghi một lần.
Input
- Dòng đầu chứa số \(n\) (\(n\leq 10^5\)).
- Dòng thứ hai chứa n số nguyên dương \(A_1,A_2,\ldots,A_n\) (\(A_i\leq 10^6\)).
Output
- Gồm \(n\) dòng, mỗi dòng ghi số hạng thứ \(A_i\) và số lần xuất hiện của chúng.
Example
Test 1
Input
9
2 3 1 2 3 4 5 4 3
Output
1 1
2 2
3 3
4 2
5 1
Comments
có ai biết cách làm bài này mà không bị tle không?
from collections import Counter
n = int(input())
A = sorted(map(int, input().split()))
x = Counter(A)
for key, value in x.items():
print(key, value)
code auto đúm
This comment is hidden due to too much negative feedback. Click here to view it.
dùng set kết hợp với map
Py thì phải 3s chứ 1s sao đc cô ???
include <iostream>
include <map>
using namespace std;
define X first
define Y second
int n, x;
map<int, int> mp;
int main() {
cin >> n;
for(int i = 0; i < n; cin >> x, ++mp[x], ++i);
for(auto it : mp) cout << it.X << " " << it.Y << "\n";
}
hmmm mảng đánh dấu,tỉa vs sort :))
This comment is hidden due to too much negative feedback. Click here to view it.
cho hết vào map, xong việc :v
mảng đánh dấu:vv
4 more comments