結果

問題 No.708 (+ー)の式
ユーザー aaaaaa
提出日時 2018-07-21 16:51:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,059 bytes
コンパイル時間 811 ms
コンパイル使用メモリ 95,496 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 00:41:13
合計ジャッジ時間 1,686 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>

using namespace std;

int func(string s) {
	int num = 0;
	string fugo = "+";

	for (int i = 0; i < s.length(); i++) {
		if (s[i] == '+' || s[i] == '-') {
			fugo = s[i];
		}
		else {
			if (fugo == "+") {
				num += (int)s[i] - 48;
			}
			else {
				num -= (int)s[i] - 48;
			}
		}
	}




	return num;
}


int main() {
	int i, j, k;
	string s;
	string kako[100];
	int cnt = 0;

	cin >> s;


	for (i = 0; i < s.length(); i++) {
		if (s[i] == '(') {
			for (j = i + 1; j < s.length(); j++) {
				if (s[j] == ')') {
					kako[cnt] = s.substr(i + 1, j - (i + 1));
					int num = func(kako[cnt]);
					cnt++;
					s.replace(i, j - i+1, to_string(num));
					i = -1;
					break;
				}
			}
		}
	}

	int sum = func(s);

	cout << sum << endl;









	getchar();
	getchar();
	return 0;
}
0