結果

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

テストケース

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

ソースコード

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 == '('){
			index++;
			val += k();
		}
		else{
			val += (int)(t - '0');
		}
	}

	cout << val << endl;

	return 0;
}
0