状況
C++の練習のためにAtCoderの簡単な問題を解いています。以下の問題で躓いたのですが理由がよく分からないので教えていただきたいです。
ABC001 B 問題ページ
気象情報は、世界中に様々な形で流れています。そのひとつの地上実況気象通報式 (SYNOP) では、視程 (肉眼で物体がはっきりと確認できる最大の距離) を、次の規則に従って、VVという値 (通報式) に変換して報じます。
- 0.1km 未満: VVの値は 00 とする。
- 0.1km 以上5km以下:距離(km)を10倍した値とする。1桁の場合は上位に0を付す。
...
これに対して私は次のようなコードを書きました。
C++
1#include <iostream> 2#include <string> 3using namespace std; 4 5int main() { 6 int m; 7 cin >> m; 8 9 if (m < 100) { 10 cout << "00"; 11 } 12 else if (100 <= m && m <= 5000) { 13 m /= 100; 14 string num; 15 if (m < 10) { 16 num = "0" + to_string(m); 17 } 18 else { 19 num = to_string(m); 20 } 21 22 cout << num << endl; 23 } 24 else if (m >= 6000 && m <= 30000) { 25 cout << m / 1000 + 50 << endl; 26 } 27 else if (m >= 35000 && m <= 70000) { 28 cout << (m - 30) / 5 + 80 << endl; 29 } 30 else { 31 cout << 89 << endl; 32 } 33}
自分の環境(Visual Studio 2017)ではきちんとコンパイルも通り、AtCoderの入力例に対しても正しい値を出力します。
しかし、提出するとコンパイルエラーになってしまいます。この時のエラーメッセージが
./Main.cpp: In function ‘int main()’: ./Main.cpp:16:27: error: ‘to_string’ was not declared in this scope num = "0" + to_string(m); ^ ./Main.cpp:19:21: error: ‘to_string’ was not declared in this scope num = to_string(m); ^
という感じになっています。to_string
のスコープが違うみたいな感じだと思うのですが、よく分かりません。
ちなみに、提出時の言語には「C++ (GCC 5.4.1)」を選んでいます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/01 22:27