fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <random>
  5. #include <unordered_map>
  6.  
  7. typedef std::vector<std::string> DType;
  8. typedef std::unordered_map<std::string, std::size_t> MType;
  9.  
  10. DType MakeVector(std::size_t N,const DType& List, unsigned int S = 0) {
  11.  
  12. std::minstd_rand mr(S);
  13. std::uniform_int_distribution<std::size_t> ui(0, List.size() - 1);
  14. DType R;
  15. for (std::size_t i = 0; i < N; i++) {
  16. R.push_back(List[ui(mr)]);
  17. }
  18. return R;
  19. }
  20.  
  21. MType MakeHoge(const DType& D) {
  22. MType R;
  23.  
  24. for (auto& o : D) {
  25. R[o]++;
  26. }
  27. return R;
  28. }
  29.  
  30. bool Show(const DType& D,const MType& M) {
  31. for (auto o : D) {
  32. std::cout << o << std::endl;
  33. }
  34. std::cout << std::endl;
  35. for (auto o : M) {
  36. std::cout << o.first << ':' << o.second << std::endl;
  37. }
  38. std::cout << std::endl;
  39. return true;
  40. }
  41.  
  42. int main() {
  43. DType W = { "hoge","huga","foo","bar" };
  44. DType D;
  45. MType R;
  46.  
  47. D=MakeVector(16, W);
  48. R = MakeHoge(D);
  49. Show(D, R);
  50.  
  51. return 0;
  52. }
Success #stdin #stdout 0s 4516KB
stdin
Standard input is empty
stdout
hoge
hoge
foo
bar
bar
hoge
foo
huga
huga
foo
hoge
foo
foo
bar
foo
foo

huga:2
bar:3
hoge:4
foo:7