#include <iostream>
#include <algorithm>
#include <map>
#include <unordered_map>
using namespace std;
int main() {
int array[]={100, 80, 90, 100, 80, 60, 80};
const int number = sizeof(array)/sizeof(int);
pair<int, size_t> result[number];
int nres=0;
cout<<"Map approach: "<<endl;
// count each element
unordered_map<int, size_t> count;
for (int i=0; i<number; i++)
count[array[i]]++;
for (auto &e:count)
cout << e.first <<" : "<<e.second<< "-> "<<e.first/e.second<<endl;
cout<<endl;
// sorting approach
std::sort(array, array + number);
int counter;
for(int i = 0; i < number; i+=counter) {
for (counter=1;i+counter<number && array[i+counter]==array[i] ; )
counter++;
if (counter>1) {
cout << "dup: " << array[i] << " "<<counter<<endl;
result[nres++] = make_pair(array[i], counter);
}
}
cout <<"---"<<endl;
for (int i=0; i<nres; i++)
cout << result[i].first <<" : "<<result[i].second<<" ->" << result[i].first/result[i].second<<endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8dW5vcmRlcmVkX21hcD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewoJaW50IGFycmF5W109ezEwMCwgODAsIDkwLCAxMDAsIDgwLCA2MCwgODB9OyAKCWNvbnN0IGludCBudW1iZXIgPSBzaXplb2YoYXJyYXkpL3NpemVvZihpbnQpOyAKCXBhaXI8aW50LCBzaXplX3Q+IHJlc3VsdFtudW1iZXJdOwoJaW50IG5yZXM9MDsgCgkKCWNvdXQ8PCJNYXAgYXBwcm9hY2g6ICI8PGVuZGw7IAoKICAgIC8vIGNvdW50IGVhY2ggZWxlbWVudAoJdW5vcmRlcmVkX21hcDxpbnQsIHNpemVfdD4gY291bnQ7ICAKCWZvciAoaW50IGk9MDsgaTxudW1iZXI7IGkrKykgCgkgICAgY291bnRbYXJyYXlbaV1dKys7ICAKCWZvciAoYXV0byAmZTpjb3VudCkgIAoJICAgIGNvdXQgPDwgZS5maXJzdCA8PCIgO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