fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int readMaxNums() {
  5. int num;
  6. cin >> num; // accept number
  7. string _;
  8. getline(cin, _);
  9. return num;
  10. }
  11.  
  12. vector<string> readNames() {
  13. vector<string> names;
  14. string name;
  15. while(getline(cin, name)) {
  16. names.push_back(name);
  17. }
  18. return names;
  19. }
  20.  
  21. int main() {
  22. // Input
  23. int max_nums = readMaxNums();
  24. vector<string> names = readNames();
  25.  
  26. // Process
  27. vector<int> numbers(max_nums);
  28. iota(numbers.begin(), numbers.end(), 1);
  29. random_shuffle(numbers.begin(), numbers.end());
  30.  
  31. vector<pair<int, string>> number_and_names;
  32. for (int i = 0; i < names.size(); i++) {
  33. number_and_names.push_back({numbers[i], names[i]});
  34. }
  35. sort(number_and_names.begin(), number_and_names.end());
  36.  
  37. // Output
  38. for (auto [number, name]: number_and_names) {
  39. cout << name <<" : " << number << endl;
  40. }
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5292KB
stdin
300
Alo semua
Betty s
Char
D
E
stdout
Char : 12
D : 70
Alo semua : 111
E : 210
Betty s : 291