fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <random>
  4. #include <algorithm>
  5.  
  6. std::vector<std::size_t> MakeRandom(std::size_t N){
  7. std::vector<std::size_t> vec(N);
  8. std::size_t i = 0;
  9.  
  10. for (auto& o : vec) o = i++;
  11.  
  12. std::random_device rd;
  13. std::mt19937 mt(rd());
  14.  
  15. std::shuffle(vec.begin(), vec.end(), mt);
  16.  
  17. return vec;
  18.  
  19. }
  20.  
  21. std::vector<std::size_t> MakeHoge(std::size_t N, std::size_t Drop = 2, bool IsShowArray = false){
  22.  
  23. auto vec = MakeRandom(N);
  24. std::vector<std::size_t> ret;
  25. int C = 0;
  26. bool IsFind = false;
  27. std::size_t j = 0;
  28.  
  29. for (std::size_t i = 0; i < Drop; i++){
  30. vec.pop_back();
  31. }
  32. if (IsShowArray == true){
  33. for (std::size_t i = 0; i < vec.size(); i++){
  34. std::cout << vec[i] << ',';
  35. }
  36. std::cout << std::endl;
  37. }
  38. for (std::size_t i = 0; i < N; i++)
  39. {
  40. IsFind = true;
  41. for (std::size_t j = 0; j < vec.size(); j++){
  42.  
  43. if (vec[j] == i){
  44. IsFind = false;
  45. break;
  46. }
  47. }
  48. if (IsFind == true){
  49. ret.push_back(i);
  50. if (ret.size() == Drop) break;
  51. }
  52. }
  53.  
  54.  
  55. return ret;
  56. }
  57. int main(){
  58. auto R = MakeHoge(16, 2, true);
  59.  
  60. std::cout << "I find Number of (";
  61. for (auto& o : R) std::cout << o << ',';
  62. std::cout << ")";
  63.  
  64. return 0;
  65. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
10,9,3,0,2,5,12,4,11,6,15,8,1,13,
I find Number of (7,14,)