Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int AP[10], IDX[10];
- void processDigit(int nr) {
- while(nr)
- {
- int c = nr % 10;
- nr = nr / 10;
- AP[c]++;
- }
- }
- void sortArrays() {
- for(int i = 0; i < 10; i++) {
- for(int j = i + 1; j < 10; j++) {
- if(AP[i] > AP[j]) {
- swap(AP[i], AP[j]);
- swap(IDX[i], IDX[j]);
- } else if(AP[i] == AP[j] && IDX[i] > IDX[j]) {
- swap(IDX[i], IDX[j]);
- }
- }
- }
- }
- int main()
- {
- for(int i = 0; i < 10; i++)
- IDX[i] = i;
- int n;
- cin >> n;
- for(int i = 0; i < n; i++)
- {
- int x;
- cin >> x;
- processDigit(x);
- }
- sortArrays();
- for(int i = 0; i < 10; i++)
- {
- if(AP[i])
- cout << IDX[i] << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement