結果
問題 |
No.222 引き算と足し算
|
ユーザー |
|
提出日時 | 2016-11-20 15:55:44 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 780 bytes |
コンパイル時間 | 1,883 ms |
コンパイル使用メモリ | 168,476 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-27 09:02:02 |
合計ジャッジ時間 | 2,570 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 3 |
other | AC * 1 WA * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; signed main(){ string S; cin >> S; int x = 0; int op = 0; 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 ); for( int i = 0; i < S.size(); ++i ) y = y * 10 + S[ i ] - '0'; y *= op; cout << x + y << endl; return 0; }