結果

問題 No.49 算数の宿題
ユーザー knkknk
提出日時 2017-09-18 12:19:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 726 bytes
コンパイル時間 906 ms
コンパイル使用メモリ 80,072 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 17:38:36
合計ジャッジ時間 1,627 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>

int main(void)
{
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(2);
  std::string s;
  std::cin >> s;
  std::vector< int > number;
  std::vector< bool > isadd;
  for (auto c : s) {
    if (c=='*') isadd.push_back(true);
    else if (c=='+') isadd.push_back(false);
    else {
      if (number.size() == isadd.size()) number.push_back(c-'0');
      else number[number.size()-1] = number[number.size()-1] * 10 + (c-'0');
    }
  }
  int ans = number[0];
  for (int i = 0; i < isadd.size(); ++i) {
    if (isadd[i]) ans += number[i+1];
    else ans *= number[i+1];
  }
  std::cout << ans << std::endl;
  return 0;
}
0