結果
問題 | No.222 引き算と足し算 |
ユーザー |
|
提出日時 | 2018-06-16 17:56:50 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 784 bytes |
コンパイル時間 | 509 ms |
コンパイル使用メモリ | 64,520 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-30 16:18:46 |
合計ジャッジ時間 | 1,528 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
#include <iostream> #include <string> using namespace std; int main(int argc, char* argv[]) { string S; cin>>S; char *pStr=(char*)S.c_str(); char ch1='+',ch2='+'; string s1,s2; switch(pStr[0]){ case '-': ch1='-'; pStr++; break; case '+': ch1='+'; pStr++; break; } char op=' '; while (*pStr!='\0'){ if (op==' '){ if (*pStr>='0' && *pStr<='9'){ s1.push_back(*pStr++); }else{ op=(*pStr++); } continue; } switch(*pStr){ case '-': case '+': ch2=(*pStr++); continue; } s2.push_back(*pStr++); } int data1=atol(s1.c_str()); int data2=atol(s2.c_str()); if (ch1=='-'){ data1=-data1; } if (ch2=='-'){ data2=-data2; } if (op=='+'){ cout<<data1-data2<<endl; }else{ cout<<data1+data2<<endl; } return 0; }