fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <random>
  5.  
  6. std::vector<int> MakeRandomArray(std::size_t N){
  7. std::random_device rd;
  8. std::mt19937 mt(rd());
  9. //std::uniform_int<> ui(0, N);
  10.  
  11. std::vector<int> vec(N);
  12.  
  13. //for (auto& o : vec) o = ui(mt);
  14. for (auto& o : vec) o = mt()%N+1;//don't write like this code!!
  15.  
  16. std::sort(vec.begin(), vec.end());
  17.  
  18. return vec;
  19. }
  20.  
  21. int CountN(std::vector<int> vec){
  22. int N = vec.size();
  23. int C = 0;
  24.  
  25. for (std::size_t i = 0; i < vec.size(); i++)
  26. {
  27. if (vec[i] == N) C++;
  28. }
  29.  
  30. return C;
  31. }
  32.  
  33. int main(){
  34.  
  35. int N = 100;
  36. auto V = MakeRandomArray(N);
  37. auto R = CountN(V);
  38.  
  39. for (auto& o : V) std::cout << o << ',';
  40. std::cout << std::endl;
  41. std::cout << "よくわからんけど" << R << "個あったような気がする。" << std::endl;
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
1,4,5,5,7,7,9,11,11,14,14,15,17,17,18,18,18,19,22,22,23,23,23,25,25,26,27,28,28,28,28,29,29,30,30,30,31,32,32,32,33,34,34,35,39,40,40,45,46,47,51,52,53,54,57,58,59,59,60,60,62,64,65,67,67,69,69,71,73,74,75,75,76,77,77,77,78,78,79,80,81,83,84,85,85,87,87,88,89,89,90,91,93,94,94,97,97,98,98,100,
よくわからんけど1個あったような気がする。