結果

問題 No.708 (+ー)の式
ユーザー EsireEsire
提出日時 2018-11-04 17:13:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,681 bytes
コンパイル時間 964 ms
コンパイル使用メモリ 93,504 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-30 21:49:13
合計ジャッジ時間 1,520 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
g++ -std=c++11 -Wall -O2 -o main.exe main.cpp
./main.exe
*/

#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <climits>
//intの最大値: INT_MAX
//longの最大値: LONG_MAX
//long longの最大値: LLONG_MAX
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <queue>
#include <stack>
//最大公約数: gcd()
//最小公倍数: lcm()

#define ll long long int

using namespace std;

template <typename T>
void sortasc(vector<T> &v){ //vectorを昇順にソート
    sort(v.begin(), v.end(), std::less<T>());
    return;
}

template <typename T>
void sortdesc(vector<T> &v){ //vectorを降順にソート
    sort(v.begin(), v.end(), std::greater<T>());
    return;
}

//------------------------------------------------------------------------------

string S;
int index;

int k(){
	int val = 0;
	char t;

	while(1){
		t = S[index++];

		if(t == ')'){
			return val;
		}
		else if(t == '+'){
			val += (int)(S[index++] - '0');
		}
		else if(t == '-'){
			val -= (int)(S[index++] - '0');
		}
		else{
			val += (int)(t - '0');
		}
	}
}

int main(){
	cin >> S;

	int val = 0;
	char t;

	index = 0;
	
	while(index < (int)(S.size())){
		t = S[index++];

		if(t == '+'){
			if(S[index] == '('){
				index++;
				val += k();
			}
			else val += (int)(S[index++] - '0');
		}
		else if(t == '-'){
			if(S[index] == '('){
				index++;
				val -= k();
			}
			else val -= (int)(S[index++] - '0');
		}
		else if(t == '('){
			val += k();
		}
		else{
			val += (int)(t - '0');
		}

		cout << val << endl;
	}

	cout << val << endl;

	return 0;
}
0