{"id":26364,"date":"2026-11-19T22:05:14","date_gmt":"2026-11-19T13:05:14","guid":{"rendered":"https:\/\/www.tyosuke20xx.com\/blog\/?p=26364"},"modified":"2026-11-19T22:05:16","modified_gmt":"2026-11-19T13:05:16","slug":"c-%e6%95%b0%e5%bd%93%e3%81%a6%e3%82%b2%e3%83%bc%e3%83%a0","status":"publish","type":"post","link":"https:\/\/www.tyosuke20xx.com\/blog\/?p=26364","title":{"rendered":"C++ \u6570\u5f53\u3066\u30b2\u30fc\u30e0"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>#include &lt;iostream>\n#include &lt;random>\n\nint main() {\n    \/\/ 1. \u521d\u671f\u5316\u51e6\u7406\uff081\u301c100\u306e\u30e9\u30f3\u30c0\u30e0\u306a\u6b63\u89e3\u3092\u751f\u6210\uff09\n    std::random_device rd;\n    std::mt19937 gen(rd());\n    std::uniform_int_distribution&lt;> dist(1, 100);\n\n    int target = dist(gen);\n    int guess = 0;\n    int attempts = 0;\n    bool isGameOver = false;\n\n    std::cout &lt;&lt; \"=== \u6570\u5f53\u3066\u30b2\u30fc\u30e0 (1\u301c100) ===\" &lt;&lt; std::endl;\n    std::cout &lt;&lt; \"\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u304c\u601d\u3044\u6d6e\u304b\u3079\u305f\u6570\u5b57\u3092\u5f53\u3066\u3066\u304f\u3060\u3055\u3044\uff01\" &lt;&lt; std::endl;\n\n    \/\/ 2. \u30b2\u30fc\u30e0\u30eb\u30fc\u30d7\uff08\u30af\u30ea\u30a2\u3059\u308b\u307e\u3067\u7e70\u308a\u8fd4\u3059\uff09\n    while (!isGameOver) {\n        std::cout &lt;&lt; \"\\n\u6570\u5b57\u3092\u5165\u529b > \";\n\n        \/\/ \u6570\u5b57\u4ee5\u5916\u306e\u4e0d\u6b63\u306a\u5165\u529b\u306b\u5bfe\u3059\u308b\u30a8\u30e9\u30fc\u51e6\u7406\n        if (!(std::cin >> guess)) {\n            std::cin.clear();\n            std::cin.ignore(10000, '\\n');\n            std::cout &lt;&lt; \"\u6709\u52b9\u306a\u6570\u5b57\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\" &lt;&lt; std::endl;\n            continue;\n        }\n\n        attempts++;\n\n        \/\/ 3. \u5224\u5b9a\u3068\u7d50\u679c\u306e\u51fa\u529b\n        if (guess &lt; target) {\n            std::cout &lt;&lt; \"\u3082\u3063\u3068\u3010\u5927\u304d\u3044\u3011\u6570\u5b57\u3067\u3059\u3002\" &lt;&lt; std::endl;\n        }\n        else if (guess > target) {\n            std::cout &lt;&lt; \"\u3082\u3063\u3068\u3010\u5c0f\u3055\u3044\u3011\u6570\u5b57\u3067\u3059\u3002\" &lt;&lt; std::endl;\n        }\n        else {\n            std::cout &lt;&lt; \"\\n\u6b63\u89e3\uff01 \" &lt;&lt; attempts &lt;&lt; \" \u56de\u76ee\u3067\u30af\u30ea\u30a2\u3057\u307e\u3057\u305f\uff01\" &lt;&lt; std::endl;\n            isGameOver = true; \/\/ \u30eb\u30fc\u30d7\u7d42\u4e86\u30d5\u30e9\u30b0\u3092\u7acb\u3066\u308b\n        }\n    }\n\n    \/\/ 4. \u7d42\u4e86\u51e6\u7406\n    std::cout &lt;&lt; \"\u30b2\u30fc\u30e0\u3092\u7d42\u4e86\u3057\u307e\u3059\u3002\u304a\u75b2\u308c\u69d8\u3067\u3057\u305f\uff01\" &lt;&lt; std::endl;\n    return 0;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[69,4],"tags":[68,3],"class_list":["post-26364","post","type-post","status-publish","format-standard","hentry","category-c-3","category-programming","tag-c-2","tag-programming"],"aioseo_notices":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/26364","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=26364"}],"version-history":[{"count":1,"href":"https:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/26364\/revisions"}],"predecessor-version":[{"id":26365,"href":"https:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/26364\/revisions\/26365"}],"wp:attachment":[{"href":"https:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}