#include <iostream> #include <sstream> #include <vector> #include <unordered_map> std::unordered_map<int, int> countSameCities(const std::vector<int>& c) { std::unordered_map<int, int> counts; for (int city : c) { counts[city]++; } return counts; } std::vector<int> numberOfStamps(std::unordered_map<int, int> &cit, const int &n) { std::vector<int> results; int count = 0; for (int k = 1; k <= n; k++) { for (auto& pair : cit) { int num = pair.second; if (k <= num) { count += (num / k) * k; } } results.push_back(count); count = 0; } return results; } int main() { int n; std::cin >> n; std::cin.ignore(); std::vector<int> cities; std::string input; std::getline(std::cin, input); std::istringstream stream(input); int num; while (stream >> num) { cities.push_back(num); } std::unordered_map<int, int> cit = countSameCities(cities); std::vector<int> results = numberOfStamps(cit, n); for (int i : results) { std::cout << i << " "; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #include <iostream> #include <sstream> #include <vector> #include <unordered_map> std::unordered_map<int, int> countSameCities(const std::vector<int>& c) { std::unordered_map<int, int> counts; for (int city : c) { counts[city]++; } return counts; } std::vector<int> numberOfStamps(std::unordered_map<int, int> &cit, const int &n) { std::vector<int> results; int count = 0; for (int k = 1; k <= n; k++) { for (auto& pair : cit) { int num = pair.second; if (k <= num) { count += (num / k) * k; } } results.push_back(count); count = 0; } return results; } int main() { int n; std::cin >> n; std::cin.ignore(); std::vector<int> cities; std::string input; std::getline(std::cin, input); std::istringstream stream(input); int num; while (stream >> num) { cities.push_back(num); } std::unordered_map<int, int> cit = countSameCities(cities); std::vector<int> results = numberOfStamps(cit, n); for (int i : results) { std::cout << i << " "; } } |