結果
| 問題 |
No.222 引き算と足し算
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-08-09 01:33:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 1,000 ms |
| コード長 | 676 bytes |
| コンパイル時間 | 2,009 ms |
| コンパイル使用メモリ | 194,228 KB |
| 最終ジャッジ日時 | 2025-01-07 11:04:45 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
string s;
cin>>s;
int n=s.size();
int i=0;
int sign=1;
if (s[i]=='+'||s[i]=='-') {
if (s[i]=='-') sign=-1;
i++;
}
int fst=0;
while (isdigit(s[i])) {
fst=10*fst+s[i]-'0';
i++;
}
fst*=sign;
sign=1;
if (s[i]=='+'||s[i]=='-') {
if (s[i]=='+') sign=-1;
i++;
}
if (s[i]=='+'||s[i]=='-') {
if (s[i]=='-') sign*=-1;
i++;
}
int snd=0;
while (i<n&&isdigit(s[i])) {
snd=10*snd+s[i]-'0';
i++;
}
snd*=sign;
cout<<fst+snd<<endl;
return 0;
}