結果
| 問題 | No.222 引き算と足し算 |
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2015-06-05 22:50:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,253 bytes |
| 記録 | |
| コンパイル時間 | 709 ms |
| コンパイル使用メモリ | 80,480 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-15 21:26:16 |
| 合計ジャッジ時間 | 1,643 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <math.h>
#include <string>
#include <list>
#include <queue>
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed;//
//cout << setprecision(6);//
string s;
cin>>s;
int op[4];
int v[4];
rep(i,4){
op[i] = 0;
v[i] = 0;
}
int OPcount = 0;
int count = 0;
bool flag = false;
int i=0;
if(s[0] == '+'){
op[OPcount] = 1;
++OPcount;
++i;
}
else if(s[0] == '-'){
op[OPcount] = -1;
++OPcount;
++i;
}else{
op[OPcount] = 1;
++OPcount;
}
for(i;i<s.size();++i){
if(s[i] == '+'){
op[OPcount] = 1;
++OPcount;
flag = true;
}
else if(s[i] == '-'){
op[OPcount] = -1;
++OPcount;
flag = true;
}
else{
if(flag == true){
flag = false;
++count;
}
v[count] = v[count] * 10 + s[i] - '0';
}
}
int a,b;
a = v[0];
b = v[1];
if( op[0] == -1){a = -1*a;}
if( op[2] == -1){b = -1*b;}
int ans;
if( op[1] == 1){
ans = a-b;
}else{
ans = a+b;
}
P(ans);
return 0;
}
IL_msta