結果
| 問題 |
No.222 引き算と足し算
|
| コンテスト | |
| ユーザー |
zaichu
|
| 提出日時 | 2016-01-21 00:01:19 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 715 bytes |
| コンパイル時間 | 1,479 ms |
| コンパイル使用メモリ | 159,224 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-15 22:09:31 |
| 合計ジャッジ時間 | 2,409 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
int mid = 1;
while(s.size() != mid){
if(s[mid] == '+' or s[mid] == '-') break;
mid++;
}
/*
int a = 0, b = 0;
int math = 1;
for(int i = mid - 1; i >= 0; i--){
if(s[i] == '-') a *= -1;
else if(s[i] == '+') continue;
else a += int(s[i] - '0') * math;
math *= 10;
}
math = 1;
for(int i = s.size() - 1; i > mid; i--){
if(s[i] == '-') b *= -1;
else if(s[i] == '+') continue;
else b += int(s[i] - '0') * math;
math *= 10;
}
*/
string x = s.substr(0,mid);
string y = s.substr(mid+1,s.size());
int a = stoi(x), b = stoi(y);
if(s[mid] == '+') cout << a - b << endl;
else cout << a + b << endl;
return 0;
}
zaichu