質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Q&A

解決済

1回答

925閲覧

[AOJ]「IPT1_11_B サイコロII」の問題で合格できません

smile_20200722

総合スコア11

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

0グッド

1クリップ

投稿2021/06/14 15:06

前提・実現したいこと

AIZU ONLINE JUDGEというサイトの「サイコロII」という問題に合格したい。

一つ目のテストケースからCompile Error(CE)が出てしまいます。
以下のソースコードは自分の環境ではSample InputしたものをSample Outputできています。

問題文につきましては、お手数をかけしますが、以下のリンクよりご確認ください。
https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/11/ITP1_11_B

エラーメッセージ

rep/code.cpp: In function ‘int main()’: rep/code.cpp:14:5: error: ‘random_device’ was not declared in this scope random_device rd; ^ rep/code.cpp:15:5: error: ‘mt19937’ was not declared in this scope mt19937 mt(rd()); ^ rep/code.cpp:16:5: error: ‘uniform_int_distribution’ was not declared in this scope uniform_int_distribution<> rand4(0, 3); ^ rep/code.cpp:16:30: error: expected primary-expression before ‘>’ token uniform_int_distribution<> rand4(0, 3); ^ rep/code.cpp:16:42: error: ‘rand4’ was not declared in this scope uniform_int_distribution<> rand4(0, 3); ^ rep/code.cpp:33:27: error: ‘mt’ was not declared in this scope int j = rand4(mt); ^

該当のソースコード

C++

1#include <bits/stdc++.h> 2using namespace std; 3 4struct dice { 5 int number[6]; 6}; 7 8struct q_table { 9 int first; 10 int second; 11}; 12 13int main() { 14 random_device rd; 15 mt19937 mt(rd()); 16 uniform_int_distribution<> rand4(0, 3); 17 18 dice d; 19 int q_count; 20 21 for(int i = 0; i < 6; i++) { 22 cin >> d.number[i]; 23 } 24 cin >> q_count; 25 q_table q[q_count]; 26 for(int i = 0; i < q_count; i++) { 27 cin >> q[i].first >> q[i].second; 28 } 29 30 for(int i = 0; i < q_count; i++) { 31 while(true) { 32 string instruction = "SNEW"; 33 int j = rand4(mt); 34 int tmp; 35 36 if(instruction[j] == 'S') { 37 // S 38 tmp = d.number[0]; 39 d.number[0] = d.number[4]; 40 d.number[4] = d.number[5]; 41 d.number[5] = d.number[1]; 42 d.number[1] = tmp; 43 } else if(instruction[j] == 'E') { 44 // E 45 tmp = d.number[0]; 46 d.number[0] = d.number[3]; 47 d.number[3] = d.number[5]; 48 d.number[5] = d.number[2]; 49 d.number[2] = tmp; 50 } else if(instruction[j] == 'N') { 51 // N 52 tmp = d.number[0]; 53 d.number[0] = d.number[1]; 54 d.number[1] = d.number[5]; 55 d.number[5] = d.number[4]; 56 d.number[4] = tmp; 57 } else if(instruction[j] == 'W') { 58 // W 59 tmp = d.number[0]; 60 d.number[0] = d.number[2]; 61 d.number[2] = d.number[5]; 62 d.number[5] = d.number[3]; 63 d.number[3] = tmp; 64 } 65 66 if(d.number[0] == q[i].first && d.number[1] == q[i].second) { 67 cout << d.number[2] << endl; 68 break; 69 } 70 } 71 } 72 return 0; 73}

[補足]以下の3行をmain関数の外に書いた場合のエラーメッセージ

random_device rd; mt19937 mt(rd()); uniform_int_distribution<> rand4(0, 3)
rep/code.cpp:13:1: error: ‘random_device’ does not name a type random_device rd; ^ rep/code.cpp:14:1: error: ‘mt19937’ does not name a type mt19937 mt(rd()); ^ rep/code.cpp:15:1: error: ‘uniform_int_distribution’ does not name a type uniform_int_distribution<> rand4(0, 3); ^ rep/code.cpp: In function ‘int main()’: rep/code.cpp:33:27: error: ‘mt’ was not declared in this scope int j = rand4(mt); ^ rep/code.cpp:33:29: error: ‘rand4’ was not declared in this scope int j = rand4(mt); ^

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

AOJで提出するときに C++11 を選べば通ると思いますよ
デフォルトの C++ がどのバージョンを示しているかわかりませんが

投稿2021/06/14 15:18

jamjam3

総合スコア165

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

smile_20200722

2021/06/15 09:36

jamjam3さん コメントありがとうございます。 C++11に変更したら合格しました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問