結果
| 問題 |
No.222 引き算と足し算
|
| コンテスト | |
| ユーザー |
tetsuzuki1115
|
| 提出日時 | 2018-03-08 18:32:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,096 bytes |
| コンパイル時間 | 823 ms |
| コンパイル使用メモリ | 89,196 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-05 08:08:27 |
| 合計ジャッジ時間 | 1,805 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;
long long MOD = 1000000007;
int func( string s ) {
int ret = 0;
queue<char> c;
for ( int i = 0; i < s.length(); i++ ) {
if ( isdigit(s[i]) ) {
string t;
while ( isdigit( s[i] ) ) {
t += s[i];
i++;
}
i--;
int a = stoi(t);
while ( !c.empty() ) {
a = c.front() == '+' ? a : -a;
c.pop();
}
ret += a;
}
else {
c.push(s[i]);
}
}
return ret;
}
int main() {
string S;
cin >> S;
bool b = false;
for ( int i = 0; i < S.length(); i++ ) {
if ( isdigit(S[i]) ) { b = true; }
else if ( b ) { S[i] = S[i] == '+' ? '-' : '+'; break; }
}
cout << func( S ) << endl;
return 0;
}
tetsuzuki1115