結果

問題 No.222 引き算と足し算
ユーザー dnish
提出日時 2017-05-14 23:57:42
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 475 bytes
コンパイル時間 1,455 ms
コンパイル使用メモリ 166,216 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-16 05:53:15
合計ジャッジ時間 2,311 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int)N;i++)
#define p(s) cout<<(s)<<endl
using namespace std;

int main(){
	string s;
	cin>>s;
	s+='?';
	int tmp=0,ans=0;
	int minus=!isdigit(s[0]);
	char c='-';
	REP(i,minus,s.size()){
		if(isdigit(s[i])){
			tmp*=10;
			tmp+=s[i]-'0';
		}else{
			if(minus) tmp=-tmp;
			if(c=='-') ans+=tmp;
			else ans-=tmp;
			c=s[i];
			tmp=0;
			if(!isdigit(s[i+1])){
				minus=true;
				i++;
			}
		}
	}
	p(ans);
	return 0;
}
0