結果

問題 No.135 とりあえず1次元の問題
コンテスト
ユーザー TLwiegehtt
提出日時 2015-07-07 17:16:08
言語 C90
(gcc 12.4.0)
コンパイル:
gcc-12 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
RE  
実行時間 -
コード長 653 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 152 ms
コンパイル使用メモリ 32,552 KB
最終ジャッジ日時 2026-02-23 18:39:41
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 9 RE * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:23:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |         scanf("%d", &n);
      |         ^~~~~~~~~~~~~~~
main.c:25:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |                 scanf("%d", &x[i]);
      |                 ^~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <stdio.h>
#include <stdlib.h>

#define INF	(9999999)

int compare_int( const void*a, const void*b){
	int ta = *(int*)a;
	int tb = *(int*)b;
	if(ta < tb){
		return -1;
	}else if(ta > tb){
		return 1;
	}
	
	return 0;
}

int main(void){
	int i,n;
	int x[100];
	int minDis = INF;
	
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d", &x[i]);
	}
	
	qsort(x, n, sizeof(int), compare_int);
	
	for(i=1;i<n-1;i++){
		int dis = x[i] - x[i-1];
		if(dis != 0 && dis < minDis ){
			minDis = dis;
		}
		dis = x[i+1] - x[i];
		if(dis != 0 && dis < minDis ){
			minDis = dis;
		}
	}
	
	if(minDis == INF){
		minDis = 0;
	}
	
	printf("%d\n", minDis);
	return 0;
}
0