結果
問題 |
No.222 引き算と足し算
|
ユーザー |
![]() |
提出日時 | 2016-09-17 20:08:37 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 526 bytes |
コンパイル時間 | 341 ms |
コンパイル使用メモリ | 22,528 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-17 08:18:32 |
合計ジャッジ時間 | 1,153 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:4:14: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 4 | fgets(str, 100, stdin); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio> int main() { char* str = new char[100]; fgets(str, 100, stdin); int a1 = 0, a2 = 0, h1 = 1, h2 = 1; if (*str == '-' || *str == '+') { if (*str == '-') { h1 = -1; } ++str; } while(*str >= '0' && *str <= '9'){ a1 = 10 * a1 + (*str - '0'); ++str; } if (*str == '+') { h2 *= -1; } ++str; if (*str == '-' || *str == '+') { if (*str == '-') { h2 *= -1; } ++str; } while (*str >= '0' && *str <= '9') { a2 = 10 * a2 + (*str - '0'); ++str; } printf("%d\n", h1*a1 + h2*a2); }