結果

問題 No.222 引き算と足し算
ユーザー btk
提出日時 2015-06-05 22:42:48
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 611 bytes
コンパイル時間 533 ms
コンパイル使用メモリ 59,352 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-15 21:25:35
合計ジャッジ時間 1,480 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	string s;
	cin >> s;
	string a,b,c,d;
	int k = 0;
	for (;; k++){
		if (s[k] != '+'&&s[k]!='-')break;
		a += s[k];
	}
	for (;; k++){
		if (s[k] == '+'||s[k] == '-')break;
		b += s[k];
	}
	for (;; k++){
		if (s[k] != '+'&&s[k] != '-')break;
		c += s[k];
	}
	for (;k<(int)s.size(); k++){
		if (s[k] == '+' || s[k] == '-')break;
		d += s[k];
	}
	if (a == "+-" || a == "-+" || a == "-")a = "-";
	else a = "";
	if (c == "++" || c == "--" || c == "+")c = "-";
	else c = "";

	cout << stoi(a+b) + stoi(c+d) << endl;

	return 0;
}
0