結果
| 問題 |
No.21 平均の差
|
| コンテスト | |
| ユーザー |
mono1977
|
| 提出日時 | 2016-11-30 22:07:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 597 bytes |
| コンパイル時間 | 133 ms |
| コンパイル使用メモリ | 22,912 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-27 14:05:05 |
| 合計ジャッジ時間 | 560 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
6 | scanf("%d %d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:10:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | scanf("%d",num+i);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include<stdio.h>
#include<limits.h>
int main(){
int n,k;
scanf("%d %d",&n,&k);
int num[n],i;
for(i=0;i<n;i++){
scanf("%d",num+i);
}
int temp,j;
/* //sort
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(num[j]<num[i]){
temp = num[j];
num[j] = num[i];
num[i] = temp;
}
}
}
*/
//ソートしなくてよさそう
int max=0,min=INT_MAX;
for(i=0;i<n;i++){
if(num[i]>max)max=num[i];
if(num[i]<min)min=num[i];
}
//最大値と最小値をそれぞれ一つだけのグループに分けた差が、平均の差の最大値
printf("%d",max-min);
return 0;
}
mono1977