結果

問題 No.5 数字のブロック
ユーザー a2011404
提出日時 2017-03-01 10:35:47
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 198 ms / 5,000 ms
コード長 453 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 21,376 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-18 10:54:39
合計ジャッジ時間 2,501 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:8:1: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 | scanf("%d%d",&BoxW,&N);
      | ^~~~~~~~~~~~~~~~~~~~~~
main.c:11:1: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 | scanf("%d",&BlockW[i]);
      | ^~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int main(void)
{

int BoxW,N,BlockW[10000],i;

scanf("%d%d",&BoxW,&N);

for(i=0;i<N;i++){
scanf("%d",&BlockW[i]);
}

int j,temp;

for(i=0;i<N;i++){
	for(j=i+1;j<N;j++){
		if( BlockW[i] > BlockW[j] ){
		temp= BlockW[i];
		BlockW[i]=BlockW[j];
		BlockW[j]=temp;
		}
	}
}

int total=0;
int count=0;

for(i=0;i<N;i++){
	total = total + BlockW[i];
	if(total <= BoxW){
		count++;
	}else{
		break;
	}
}

printf("%d\n",count);

return 0;
}

0