結果

問題 No.708 (+ー)の式
ユーザー focusfocus
提出日時 2018-08-13 13:54:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 627 bytes
コンパイル時間 508 ms
コンパイル使用メモリ 63,932 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 16:40:16
合計ジャッジ時間 1,181 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int func()':
main.cpp:34:1: warning: control reaches end of non-void function [-Wreturn-type]
   34 | }
      | ^

ソースコード

diff #

#include<iostream>
using ll = long long;
using namespace std;
string str;
int i=0;
int func();
int calc(){
    int num = func();
    while(1){
        if(str[i]=='+'){
            i++;
            num+=func();
        }
        else if(str[i]=='-'){
            i++;
            num-=func();
        }
        else    return num; 
    }
}

int func(){
    if('0'<=str[i]&&str[i]<='9'){
        int res=str[i]-'0';
        i++;
        return res;
    }
    if(str[i]=='('){
        i++;
        int res=calc();
        i++;
        return res;
    }
}

int main(){
    cin >> str;
    cout << calc() << endl;
    return 0;
}


0