結果

問題 No.281 門松と魔法(1)
コンテスト
ユーザー NTstu
提出日時 2016-06-14 18:56:04
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 768 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 267 ms
コンパイル使用メモリ 50,424 KB
実行使用メモリ 7,976 KB
最終ジャッジ日時 2026-05-07 01:12:52
合計ジャッジ時間 1,781 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 39 WA * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 main.cpp:1:
/usr/include/stdio.h:667:14: note: declared here
  667 | extern char *gets (char *__s) __wur __attribute_deprecated__;
      |              ^~~~
main.cpp:18:13: warning: 'char* gets(char*)' is deprecated [-Wdeprecated-declarations]
   18 |         gets(str);
      |         ~~~~^~~~~
/usr/include/stdio.h:667:14: note: declared here
  667 | extern char *gets (char *__s) __wur __attribute_deprecated__;
      |              ^~~~
main.cpp:20:13: warning: 'char* gets(char*)' is deprecated [-Wdeprecated-declarations]
   20 |         gets(str);
      |         ~~~~^~~~~
/usr/include/stdio.h:667:14: note: declared here
  667 | extern char *gets (char *__s) __wur __attribute_deprecated__;
      |              ^~~~
main.cpp:22:13: warning: 'char* gets(char*)' is deprecated [-Wdeprecated-declarations]
   22 |         gets(str);
      |         ~~~~^~~~~
/usr/include/stdio.h:667:14: note: declared here
  667 | extern char *gets (char *__s) __wur __attribute_deprecated__;
      |              ^~~~
/usr/bin/ld: /tmp/ccsloQAf.o: in function `main':
main.cpp:(.text.startup+0xe): 警告: the `gets' function is dangerous and should not be used.

ソースコード

diff #
raw source code

#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)
				count = r + 1;
			else
				count = l + 1;



	}
	if ((left == 0 && center == 0) || (right == 0 && center == 0))
		count = -1;

	printf("%ld", count);

	return 0;

}
0