結果

問題 No.135 とりあえず1次元の問題
ユーザー monburan_0401
提出日時 2018-09-15 15:56:02
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 739 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 31,360 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-18 05:59:57
合計ジャッジ時間 1,362 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'main':
main.c:28:23: warning: passing argument 4 of 'qsort' from incompatible pointer type [-Wincompatible-pointer-types]
   28 |         qsort(num,N,4,c);
      |                       ^
      |                       |
      |                       int (*)(int *, int *)
In file included from main.c:3:
/usr/include/stdlib.h:839:34: note: expected '__compar_fn_t' {aka 'int (*)(const void *, const void *)'} but argument is of type 'int (*)(int *, int *)'
  839 |                    __compar_fn_t __compar) __nonnull ((1, 4));
      |                    ~~~~~~~~~~~~~~^~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int c(int*a,int*b){return*a-*b;}

int main(void){
	int N;
	int num[100000];
	int min = 10000000;		//	求める最小値
	int L;			//	差の絶対値(2点間の距離)
	
	scanf("%d",&N);
	for(int i = 0; i < N; i++){
		scanf("%d",&num[i]);
	}
	
/*	int change;
	for(int i = 0; i < N-1; i++){
	    for(int j = i; j < N; j++){
	        if(num[i] > num[j]){
	            change = num[i];
	            num[i] = num[j];
	            num[j] = change;
	        }
	    }
	}
*/
	qsort(num,N,4,c);
	
	for(int k = 0; k < N-1; k++){
		L = abs(num[k+1] - num[k]);
		if( (min > L)&&(L != 0) ){
			min = L;
		}
	}
	
	if(min == 10000000){
		min = 0;
	}
	
	printf("%d\n",min);
	return 0;
}
		
		
		
0