結果

問題 No.135 とりあえず1次元の問題
ユーザー HiroakiSoftwareHiroakiSoftware
提出日時 2015-01-26 01:05:25
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,131 bytes
コンパイル時間 448 ms
コンパイル使用メモリ 23,680 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-11 00:34:04
合計ジャッジ時間 13,281 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,248 KB
testcase_02 WA -
testcase_03 AC 2 ms
5,248 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2,461 ms
5,376 KB
evil01.txt AC 2,471 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |         scanf ( "%d" , &BufNums );
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:23:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |                 scanf ( "%d" , &Current);
      |                 ~~~~~~^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>



int *pX = nullptr;
int N = 0;



int main ( void ) {

	int BufNums;


	scanf ( "%d" , &BufNums );

	pX = new int [ BufNums ];
	N = 0;
	int Current;
	bool bExistNumber;

	for ( int i = 0; i < BufNums; i++ ) {
		scanf ( "%d" , &Current);
		bExistNumber = false;

		/*for ( int j = 0; j < N; j++ ) {
			if ( Current == *( pX + j ) ) {
				bExistNumber = true;
				break;
			}
		}*/

		if ( bExistNumber == false ) {
			*( pX + N ) = Current;
			N++;
		}
	}



	if ( N != 1 ) {

		int MinNum;
		int buf;
		for ( int i = 0; i < (N-1); i++ ) {

			MinNum = i;
			for ( int j = i+1; j < N; j++ ) {
				if ( *( pX + i )  > *( pX + j ) ) MinNum = j;
			}

			buf = *( pX + i );
			*( pX + i ) = *( pX + MinNum );
			*( pX + MinNum ) = buf;
		}

		int diff = 0 , diffbuf;
		
		diff = *( pX + 0 ) - *( pX +  1 );
		if ( diff < 0 )diff *= -1;

		for ( int i = 1; i < N - 1; i++ ) {
			diffbuf = *( pX + i ) - *( pX + i + 1 );
			if ( diffbuf < 0 )diffbuf *= -1;
			if ( ( diff == 0 ) || ( diff > diffbuf ) ) diff = diffbuf;
		}


		printf ( "%d\n" , diff );
	} else {
		printf ( "0\n" );

	}


	delete []pX;

	return 0;
}
0