結果

問題 No.222 引き算と足し算
ユーザー ohreitetsuohreitetsu
提出日時 2018-06-16 17:56:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 784 bytes
コンパイル時間 461 ms
コンパイル使用メモリ 65,948 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 06:08:47
合計ジャッジ時間 1,646 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	string S;
	cin>>S;
	char *pStr=(char*)S.c_str();
	char ch1='+',ch2='+';
	string s1,s2;
	switch(pStr[0]){
		case '-':
			ch1='-';
			pStr++;
			break;
		case '+':
			ch1='+';
			pStr++;
			break;
	}
	char op=' ';
	while (*pStr!='\0'){
		if (op==' '){
			if (*pStr>='0' && *pStr<='9'){
				s1.push_back(*pStr++);
			}else{
				op=(*pStr++);
			}
			continue;
		}
		switch(*pStr){
			case '-':
			case '+':
				ch2=(*pStr++);
				continue;
		}
		s2.push_back(*pStr++);
	}
	int data1=atol(s1.c_str());
	int data2=atol(s2.c_str());
	if (ch1=='-'){
		data1=-data1;
	}
	if (ch2=='-'){
		data2=-data2;
	}
	if (op=='+'){
		cout<<data1-data2<<endl;
	}else{
		cout<<data1+data2<<endl;
	}
	return 0;
}
0