結果
| 問題 |
No.222 引き算と足し算
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2016-03-28 12:45:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,062 bytes |
| コンパイル時間 | 628 ms |
| コンパイル使用メモリ | 84,384 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-15 22:10:21 |
| 合計ジャッジ時間 | 1,616 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 222.cc: No.222 引き算と足し算 - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
/* typedef */
/* global variables */
/* subroutines */
int num(string &s, int &pos) {
int n = 0, sign = 1;
if (s[pos] == '+') pos++;
else if (s[pos] == '-') sign = -1, pos++;
while (pos < s.size() && s[pos] >= '0' && s[pos] <= '9')
n = n * 10 + s[pos++] - '0';
return n * sign;
}
int expr(string &s, int &pos) {
int e0 = num(s, pos);
while (pos < s.size()) {
char op = s[pos++];
int e1 = num(s, pos);
if (op == '+') e0 -= e1;
else e0 += e1;
}
return e0;
}
/* main */
int main() {
string s;
cin >> s;
int pos = 0;
int ans = expr(s, pos);
printf("%d\n", ans);
return 0;
}
tnakao0123