結果

問題 No.49 算数の宿題
ユーザー alpha_virginisalpha_virginis
提出日時 2015-06-20 22:28:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 828 bytes
コンパイル時間 1,144 ms
コンパイル使用メモリ 144,528 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-24 17:26:17
合計ジャッジ時間 1,801 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>


int main() {

  long ans;
  std::string tstr;
  char str[128];
  long p = 0;
  long N;
  long temp;
  char ope;

  std::cin >> tstr;
  strcpy( str, tstr.c_str() );
  N = tstr.size();

  p = 0;
  temp = 0;
  for(int i = p; i < N; ++i) {
    if( not ( '0' <= str[i] and str[i] <= '9' ) ) {
      p = i;
      break;
    }
    temp *= 10;
    temp += str[i] - '0';
  }
  ans = temp;

  for(;;) {
    if( p >= N ) { break; }
    ope = str[p];
    p += 1;
    temp = 0;
    for(int i = p; i < N; ++i) {
      if( not ( '0' <= str[i] and str[i] <= '9' ) ) {
	p = i;
	break;
      }
      temp *= 10;
      temp += str[i] - '0';
    }
    switch( ope ) {
    case '+':
      ans *= temp;
      break;
    case '*':
      ans += temp;
      break;
    }
  }

  std::cout << ans << std::endl;
  
  return 0;
}
0