結果

問題 No.5 数字のブロック
ユーザー TLwiegehtt
提出日時 2015-07-06 22:55:02
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 168 ms / 5,000 ms
コード長 514 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 20,992 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-17 22:57:58
合計ジャッジ時間 2,145 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
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", &L);
      |         ^~~~~~~~~~~~~~~
main.c:24:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |         scanf("%d", &N);
      |         ^~~~~~~~~~~~~~~
main.c:27:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |                 scanf("%d", &W[i]);
      |                 ^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

void bubble(int len, int *W){
	int i,j;
	for(i=0;i<len;i++){
		for(j=i+1;j<len;j++){
			if( W[i] > W[j] ){
				int tmp = W[i];
				W[i] = W[j];
				W[j] = tmp;
			}
		}
	}
}

int main(void){
	int i;
	int L, N;
	int W[10100];
	
	int sum = 0;
	int count = 0;
	scanf("%d", &L);
	scanf("%d", &N);
	
	for(i=0;i<N;i++){
		scanf("%d", &W[i]);
	}
	
	bubble(N, W);
	
	for(i=0;i<N;i++){
		if( (sum+W[i]) > L ){
			break;
		}else{
			count++;
			sum += W[i];
		}
	}
	
		printf("%d\n", count);
	return 0;
}
0