結果
| 問題 |
No.222 引き算と足し算
|
| コンテスト | |
| ユーザー |
wahr69
|
| 提出日時 | 2015-08-04 14:23:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 759 bytes |
| コンパイル時間 | 565 ms |
| コンパイル使用メモリ | 57,728 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-15 22:03:24 |
| 合計ジャッジ時間 | 1,447 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
#include <iostream>
#include <string>
using namespace std;
int getValue(string input, int* offset) {
int x = 0;
int flag1 = 1;
int index = *offset;
if (input[index] == '+') {
flag1 = 1;
++index;
} else if (input[index] == '-') {
flag1 = -1;
++index;
}
for (int i = 0; i < input.length(); ++i) {
if (input[index] < '0' || input[index] > '9') {
break;
}
x *= 10;
x += input[index] - '0';
++index;
}
x *= flag1;
*offset = index;
return x;
}
int main() {
string input = "";
cin >> input;
int offset = 0;
int x = getValue(input, &offset);
char op = input[offset];
++offset;
int y = getValue(input, &offset);
if (op == '+') {
cout << x - y << endl;
} else {
cout << x + y << endl;
}
getchar();
getchar();
}
wahr69