結果
| 問題 |
No.222 引き算と足し算
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-12-16 03:20:25 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 799 bytes |
| コンパイル時間 | 1,533 ms |
| コンパイル使用メモリ | 158,420 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-15 22:08:32 |
| 合計ジャッジ時間 | 2,068 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i, n) for(int(i)=0;(i)<(n);++(i))
#define in(T,V) T V;cin>>V;
const int MOD = int(1e9+7);
char getop(string::const_iterator &it){
if(*it == '-' || *it == '+'){
return *it++;
}
return '+';
}
int getnum(string::const_iterator &it){
int n = 0;
while(isdigit(*it)){
char c = *it++;
n = n * 10 + (c - '0');
}
return n;
}
int main(){
in(string,s);
auto it = s.cbegin();
auto op1 = getop(it);
auto num1 = getnum(it);
auto op = getop(it);
auto op2 = getop(it);
auto num2 = getnum(it);
if(op1 == '-') num1 = -num1;
if(op2 == '-') num2 = -num2;
if(op == '+') num2 = -num2;
cout << num1 + num2 << endl;
}