Bài 21. Đếm số lần xuất hiện của mỗi phần tử trong dãy số. Ví dụ:
XUATHIEN.INP |
XUATHIEN.OUT |
6 3 5 3 6 5 7 |
3 2 5 2 6 1 7 1 |
Code tham khảo:
#include <iostream>
using namespace std;
int main() {
freopen("XUATHIEN.INP","r",stdin);
freopen("XUATHIEN.OUT","w",stdout);
int n, a[1000], b[1000];
cin >> n;
for(int i=0; i<n; i++) {
cin >> a[i];
b[i] = 1;
}
for(int i=0; i<n; i++) {
int d = 1;
if(b[i]) {
b[i] = 0;
for (int j=i+1; j<n; j++)
if(a[j] == a[i]) {
d++;
b[j] = 0;
}
cout << a[i] << " " << d << endl;
}
}
return 0;
}
You really make it appear really easy along with your presentation however I find this topic to be actually one thing that I believe I’d never understand.
It sort of feels too complex and very broad for me.
I’m taking a look ahead to your subsequent post, I’ll attempt to get the cling of it!
Lista escape room
Very interesting subject, thank you for putting up..
Very interesting details you have noted, appreciate it for posting.
Euro travel guide