結果
問題 | No.222 引き算と足し算 |
ユーザー |
![]() |
提出日時 | 2015-06-05 22:45:29 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 433 bytes |
コンパイル時間 | 477 ms |
コンパイル使用メモリ | 66,244 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-15 21:25:37 |
合計ジャッジ時間 | 1,397 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:16:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 16 | char s[21];scanf("%s",s); | ~~~~~^~~~~~~~ main.cpp:20:12: warning: ‘op’ may be used uninitialized in this function [-Wmaybe-uninitialized] 20 | if(*op=='+')printf("%d\n",a-b);else printf("%d\n",a+b); | ^~~
ソースコード
#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <iostream> #include <map> #include <vector> #include <queue> #include <set> using namespace std; //namaega184 int main(){ char s[21];scanf("%s",s); int len=strlen(s);char *op; for(int i=1;i<len;i++)if(s[i]=='+'||s[i]=='-'){op=&s[i];break;} int a=atoi(s),b=atoi(op+1); if(*op=='+')printf("%d\n",a-b);else printf("%d\n",a+b); return 0; }