結果

問題 No.49 算数の宿題
ユーザー tottoripapertottoripaper
提出日時 2014-11-24 05:38:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 566 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 53,844 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-24 17:24:01
合計ジャッジ時間 1,034 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,504 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,504 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:13: warning: ‘first’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     for(int i=first+1;i<(int)S.size();){
             ^
main.cpp:17:16: warning: ‘a’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         else{a += b;}
              ~~^~~~

ソースコード

diff #

#include <iostream>

int main(){
    std::string S;
    std::cin >> S;

    int a, first;
    for(int i=0;i<(int)S.size();i++){
        if(S[i] == '+' || S[i] == '*'){a = std::stoi(S.substr(0, i)); first = i; break;}
    }

    for(int i=first+1;i<(int)S.size();){
        while(i < (int)S.size() && S[i] != '+' && S[i] != '*'){i += 1;}
        
        int b = std::stoi(S.substr(first+1, i-(first+1)));
        if(S[first] == '+'){a *= b;}
        else{a += b;}

        first = i;
        i += 1;
    }

    std::cout << a << std::endl;
}
0