Advertisement
Naohiro19

C++11時代の数あてゲーム

Feb 13th, 2022
904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. /*
  2. http://www.kumei.ne.jp/c_lang/cpp/cpp_92.htm
  3.  
  4. のあるプログラムはいわゆるC++03時代にある非推奨となった関数が利用されているので。
  5. C++11時代のプログラムに変えてみました。
  6. */
  7.  
  8. #include <iostream>
  9. #include <random>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <numeric>
  13.  
  14.  
  15. int main()
  16. {
  17.     std::vector<int> v(100);
  18.     std::iota(v.begin(), v.end(), 1);
  19.  
  20.     std::mt19937 engine{ std::random_device{}() };
  21.     std::shuffle(v.begin(), v.end(), engine);
  22.  
  23.     int x;
  24.     while (1) {
  25.         std::cout << "1から100までの数字を入力>";
  26.         std::cin >> x;
  27.         if (x < v[0]) {
  28.             std::cout << "小さすぎます。" << std::endl;
  29.         }
  30.         else if (x > v[0]) {
  31.             std::cout << "大きすぎます。" << std::endl;
  32.         }
  33.         else {
  34.             std::cout << "正解!" << std::endl;
  35.             break;
  36.         }
  37.     }
  38.    
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement