結果
問題 | No.222 引き算と足し算 |
ユーザー |
|
提出日時 | 2016-11-20 16:01:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 862 bytes |
コンパイル時間 | 1,528 ms |
コンパイル使用メモリ | 169,320 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-27 09:02:13 |
合計ジャッジ時間 | 2,350 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
#include <bits/stdc++.h> using namespace std; signed main(){ string S; cin >> S; int x = 0; int op = 0; if( S[ 0 ] == '+' ) S = S.substr( 1 ); if( S[ 0 ] == '-' ){ for( int i = 1; i < S.size(); ++i ){ if( S[ i ] == '-' or S[ i ] == '+' ){ op = ( S[ i ] == '+' ? -1 : 1 ); S = S.substr( i + 1 ); break; } x = x * 10 + S[ i ] - '0'; } x = -x; } else{ for( int i = 0; i < S.size(); ++i ){ if( S[ i ] == '-' or S[ i ] == '+' ){ op = ( S[ i ] == '+' ? -1 : 1 ); S = S.substr( i + 1 ); break; } x = x * 10 + S[ i ] - '0'; } } int y = 0; if( S[ 0 ] == '-' ) op *= -1, S = S.substr( 1 ); if( S[ 0 ] == '+' ) S = S.substr( 1 ); for( int i = 0; i < S.size(); ++i ) y = y * 10 + S[ i ] - '0'; y *= op; cout << x + y << endl; return 0; }