結果

問題 No.5 数字のブロック
ユーザー sasa
提出日時 2025-02-28 16:45:21
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 609 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 25,856 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-02-28 16:45:25
合計ジャッジ時間 2,914 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 WA * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:7:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |     scanf("%d", &bigbox);
      |     ^~~~~~~~~~~~~~~~~~~~
main.c:9:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |     scanf("%d", &len);
      |     ^~~~~~~~~~~~~~~~~
main.c:13:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         scanf("%d",&val[i]);
      |         ^~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

int main(void){
    // 大きい箱
    int bigbox = 0;
    scanf("%d", &bigbox);
    int len = 0;
    scanf("%d", &len);
    
    int val[len]; 
    for(int i = 0;i < len;i++){
    	scanf("%d",&val[i]);
    }
    
    int *p = val;
    
	for (int i = 0; i < len; i++)
	{
		for (int j = 0; j < len; j++)
		{
			//比較元より大きければ入れ替える
			if (p[i] < p[j])
			{
				int x = p[j];
				p[j] = p[i];
				p[i] = x;
			}
		}
	}
	int sum = 0;
	int count = 0;
	while(sum < bigbox){
    	sum += p[count];
    	count++;
    }
    printf("%d",count);
    
}
0