結果

問題 No.49 算数の宿題
ユーザー itezpaceitezpace
提出日時 2016-08-08 09:05:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 931 bytes
コンパイル時間 484 ms
コンパイル使用メモリ 53,944 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 17:33:34
合計ジャッジ時間 1,150 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:51:3: warning: ‘o’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   if(o==0){
   ^~

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;
int main(){
  string s,a,b;
  cin>>s;
  int f,o;
  f=0;
  int x,y,z;
  for(int i=0; i<s.size(); ++i){
    if(s[i]=='*'){
      if(f==0){
        f=1;
      } else {
        x=stoi(a);
        y=stoi(b);
        if(o==0){
          z=x+y;
        } else {
          z=x*y;
        }
        a.clear();
        a+=to_string(z);
        b.clear();
      }
      o=0;
    } else if(s[i]=='+'){
      if(f==0){
        f=1;
      } else {
        x=stoi(a);
        y=stoi(b);
        if(o==0){
          z=x+y;
        } else {
          z=x*y;
        }
        a.clear();
        a+=to_string(z);
        b.clear();
      }
      o=1;
    } else if(f==0){
      a+=s[i];
    } else if(f==1){
      b+=s[i];
    }
  }
  x=stoi(a);
  y=stoi(b);
  if(o==0){
    z=x+y;
  } else {
    z=x*y;
  }
  a.clear();
  a+=to_string(z);
  b.clear();
  cout<<stoi(a)<<endl;
  return 0;
}
0