結果
| 問題 |
No.222 引き算と足し算
|
| コンテスト | |
| ユーザー |
aya_shameimaru
|
| 提出日時 | 2015-06-05 23:00:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,518 bytes |
| コンパイル時間 | 920 ms |
| コンパイル使用メモリ | 83,056 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-15 21:27:20 |
| 合計ジャッジ時間 | 1,587 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <cstdio>
#include <string.h>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i, n) for(int i=(n)-1;i>=0;i--)
#define FOR(i, b, e) for(int i = b; i < e; i++)
#define to_bit(i) static_cast< bitset<8> >(i)
#define INF (1<<28)
#define EPS 1e-9
int main(int argc, const char * argv[]){
// cout << (int)'+' << endl;
// cout << (int)'-' << endl;
// cout << (int)'0' << endl;
string str;
cin >> str;
FOR(i, 1, str.length()){
if(str[i-1] >= '0'){
if(str[i] == '-'){
str[i] = '+';
}else if(str[i] == '+'){
str[i] = '-';
}
}
}
// cout << str << endl;
int ans = 0;
int num = 0;
int op = 1;
REP(i,str.length()){
switch (str[i]) {
case '+':
ans += op * num;
if(num != 0) op = 1;
num = 0;
break;
case '-':
ans += op * num;
if(num != 0) op = 1;
num = 0;
op *= -1;
break;
default:
num *= 10;
num += (int)(str[i] - '0');
break;
}
}
ans += op * num;
cout << ans << endl;
}
aya_shameimaru