結果

問題 No.222 引き算と足し算
コンテスト
ユーザー hotpepsi
提出日時 2015-06-06 00:10:24
言語 C++11
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 1,000 ms
+ 939µs
コード長 479 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 438 ms
コンパイル使用メモリ 87,888 KB
実行使用メモリ 9,872 KB
最終ジャッジ日時 2026-11-13 11:18:15
合計ジャッジ時間 2,303 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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