Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- http://www.kumei.ne.jp/c_lang/cpp/cpp_92.htm
- のあるプログラムはいわゆるC++03時代にある非推奨となった関数が利用されているので。
- C++11時代のプログラムに変えてみました。
- */
- #include <iostream>
- #include <random>
- #include <algorithm>
- #include <vector>
- #include <numeric>
- int main()
- {
- std::vector<int> v(100);
- std::iota(v.begin(), v.end(), 1);
- std::mt19937 engine{ std::random_device{}() };
- std::shuffle(v.begin(), v.end(), engine);
- int x;
- while (1) {
- std::cout << "1から100までの数字を入力>";
- std::cin >> x;
- if (x < v[0]) {
- std::cout << "小さすぎます。" << std::endl;
- }
- else if (x > v[0]) {
- std::cout << "大きすぎます。" << std::endl;
- }
- else {
- std::cout << "正解!" << std::endl;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement