結果

問題 No.222 引き算と足し算
ユーザー hotpepsi
提出日時 2015-06-06 00:10:24
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 479 bytes
コンパイル時間 508 ms
コンパイル使用メモリ 61,624 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-15 21:29:22
合計ジャッジ時間 1,573 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>
#include <cstring>

using namespace std;

int main(int argc, char *argv[]) {
	string s;
	getline(cin, s);
	int a = atoi(s.c_str());
	int b;
	const char *p = s.c_str();
	while (!isdigit(*p)) {
		++p;
	}
	while (isdigit(*p)) {
		++p;
	}
	if (isdigit(p[1]) || p[1] == '+') {
		b = atoi(p + 1);
	} else {
		b = -atoi(p + 2);
	}
	int ans = *p == '+' ? (a - b) : (a + b);
	cout << ans << endl;
	return 0;
}
0