結果

問題 No.5 数字のブロック
コンテスト
ユーザー a2011404
提出日時 2017-03-01 10:30:42
言語 C90
(gcc 12.4.0)
コンパイル:
gcc-12 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 549 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 93 ms
コンパイル使用メモリ 21,420 KB
最終ジャッジ日時 2026-02-01 10:27:02
合計ジャッジ時間 926 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.c: In function ‘main’:
main.c:25:1: error: C++ style comments are not allowed in ISO C90
   25 | //for(i=0;i<N;i++)              /*並び替え確認*/
      | ^
main.c:25:1: note: (this will be reported only once per input file)
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 #
raw source code

#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;
		}
	}
}
//for(i=0;i<N;i++)		/*並び替え確認*/
//printf("%d\n",BlockW[i]);


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