#include <iostream> #include <string> #include <vector> #include <sstream> #include <map> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); vector<int> integers; int n; cin >> n; cin.ignore(); string input; getline(cin, input); istringstream iss(input); int num; while (iss >> num) { integers.push_back(num); } // Count occurrences map<int, int> occurrences; for (int numb : integers) { occurrences[numb]++; } string result = ""; int resultForK = 0; for(int k = 1; k <= n; k++) { for ( const auto &p : occurrences ) { resultForK += (int)(p.second/k); } result += to_string(k * resultForK) + ' '; resultForK = 0; } cout << result << "\n"; return 0; }
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 | #include <iostream> #include <string> #include <vector> #include <sstream> #include <map> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); vector<int> integers; int n; cin >> n; cin.ignore(); string input; getline(cin, input); istringstream iss(input); int num; while (iss >> num) { integers.push_back(num); } // Count occurrences map<int, int> occurrences; for (int numb : integers) { occurrences[numb]++; } string result = ""; int resultForK = 0; for(int k = 1; k <= n; k++) { for ( const auto &p : occurrences ) { resultForK += (int)(p.second/k); } result += to_string(k * resultForK) + ' '; resultForK = 0; } cout << result << "\n"; return 0; } |