Gửi bài giải
Điểm:
1,00 (OI)
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
256M
Input:
stdin
Output:
stdout
Tác giả:
Nguồn bài:
Dạng bài
Ngôn ngữ cho phép
C, C#, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
Cho mảng số nguyên A[] gồm N phần tử, hãy liệt kê các giá trị xuất hiện trong mảng kèm theo tần suất tương ứng, mỗi giá trị chỉ liệt kê một lần theo thứ tự xuất hiện.
Đầ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^3
Đầu ra
In ra nhiều dòng, mỗi dòng gồm giá trị kèm theo tần suất tương ứng
Ví dụ :
Input 01
7
4 2 6 3 0 7 7
Output 01
4 1
2 1
6 1
3 1
0 1
7 2
Input 02
5
1 1 1 1 1
Output 02
1 5
Bình luận
include <bits/stdc++.h>
define ll long long
define fi first
define se second
define pa pair<int,int>
define vec vector<int>
define el cout<<'\n'
define fast iosbase::syncwith_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
void doc(){ fast freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); }
int n;
int main(){ //doc(); map <int, int> freq; vec val; cin>>n; for(int i=1; i<=n; i++){ int x; cin>>x; if(freq[x] == 0) val.push_back(x); freq[x]++; } for(auto it : val){ cout<<it<<" "<<freq[it]; el; } return 0; }
include <iostream>
using namespace std;
int main() { ios::syncwithstdio(false); cin.tie(0);
}
Không dùng set, map
include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5+1;
int main(){ int n; cin >> n; int a[n], b[MAX+1]; for(int i = 0; i < n; i++){ cin >> a[i]; b[a[i]]++; }
}
include <bits/stdc++.h>
using namespace std;
int a[1003];
int main() { iosbase::syncwith_stdio(0); cin.tie(NULL);
}
ý tưởng: sử dụng mảng đánh dấu + mảng phụ Mảng phụ dùng để đưa các giá trị khác nhau vào sau đó duyệt rồi in ra theo thứ tự.
include <bits/stdc++.h>
using namespace std; int main() { int n; cin >> n; int arr[n];
}
a = int(input()) b = list(map(int, input().split())) c = [0] * (10**3 + 1) for i in b: c[i] += 1 for i in range (len(b)): flag = True for j in range (0, i): if(b[j] == b[i]): flag = False break if(flag): print(b[i], c[b[i]])
include <iostream>
define N 10005
using namespace std; int a[N],b[N]={0}; int main() { int n;cin>>n; for (int i=1;i<=n;i++)cin>>a[i]; for (int i=1;i<=n;i++) if (b[i]==0) { int d=0; for (int j=1;j<=n;j++) if (a[i]==a[j]) { d++; b[j]=1; } cout <<a[i]<<" "<<d<
include <bits/stdc++.h>
define N 1005
using namespace std; int a[N]; int main() { int n;cin>>n; for (int i=1; i<=n; i++)cin>>a[i]; for (int i=1;i<=n;i++) {int kt = true; for (int j=1;j<i;j++) if (a[i]==a[j]) {kt = false; break;}
if (kt) cout<<a[i]<<" ";} return 0; }
mọi người tham khảo nhé!
#include <iostream>
using namespace std;
int find(int n, int* arr, int value) { int tmp = 0; for(int i = 0; i < n; i++) { if(arr[i] == value) { tmp++; } } return tmp; }
int main() {
}