結果
| 問題 | 
                            No.281 門松と魔法(1)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-06-14 19:04:00 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 863 bytes | 
| コンパイル時間 | 375 ms | 
| コンパイル使用メモリ | 30,592 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-11-06 20:12:20 | 
| 合計ジャッジ時間 | 1,758 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 43 WA * 14 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:16:13: warning: ‘char* gets(char*)’ is deprecated [-Wdeprecated-declarations]
   16 |         gets(str);
      |         ~~~~^~~~~
In file included from /usr/include/stdio.h:894,
                 from main.cpp:1:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:240:1: note: declared here
  240 | gets (char *__str)
      | ^~~~
main.cpp:18:13: warning: ‘char* gets(char*)’ is deprecated [-Wdeprecated-declarations]
   18 |         gets(str);
      |         ~~~~^~~~~
In file included from /usr/include/stdio.h:894,
                 from main.cpp:1:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:240:1: note: declared here
  240 | gets (char *__str)
      | ^~~~
main.cpp:20:13: warning: ‘char* gets(char*)’ is deprecated [-Wdeprecated-declarations]
   20 |         gets(str);
      |         ~~~~^~~~~
In file included from /usr/include/stdio.h:894,
                 from main.cpp:1:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:240:1: note: declared here
  240 | gets (char *__str)
      | ^~~~
main.cpp:22:13: warning: ‘char* gets(char*)’ is deprecated [-Wdeprecated-declarations]
   22 |         gets(str);
      |         ~~~~^~~~~
In file included from /usr/include/stdio.h:894,
                 from main.cpp:1:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:240:1: note: declared here
  240 | gets (char *__str)
      | ^~~~
main.cpp:16:13: warning: ignoring return value of ‘char* gets(char*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |         gets(str);
      |         ~~~~^~~~~
main.cpp:18:13: warning: ignoring return value of ‘char* gets(char*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |         gets(str);
      |         ~~~~^~~~~
main.cpp:20:13: warning: ignoring return value of ‘char* gets(char*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         gets(str);
      |         ~~~~^~~~~
main.cpp:22:13: warning: ignor
            
            ソースコード
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main() {
	int d = 0;
	long int left = 0;
	long int center = 0;
	long int right = 0;
	char str[20];
	long int count = 0;
	gets(str);
	d = atoi(str);
	gets(str);
	left = atoi(str);
	gets(str);
	center = atoi(str);
	gets(str);
	right = atoi(str);
	if (d == 0) {
		count = -1;
		printf("%ld", count);
		return 0;
	}
	if (!((center < left && center < right) || (center > left && center > right))) {
		long int lc = left - center;
		long int rc = right - center;
		long int l = abs(lc) / d;
		long int r = abs(rc) / d;
		if (l > r) {
			if (right != 0)
				count = r + 1;
			else
				count = l + 1;
		} else {
			if (left != 0)
				count = l + 1;
			else
				count = r + 1;
		}
	}
	if ((left == 0 && center == 0) || (right == 0 && center == 0))
		count = -1;
	printf("%ld", count);
	return 0;
}