結果

問題 No.5 数字のブロック
ユーザー Maeda
提出日時 2025-03-03 09:53:46
言語 C
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 517 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 25,728 KB
実行使用メモリ 8,612 KB
最終ジャッジ日時 2025-03-03 09:53:52
合計ジャッジ時間 6,004 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other RE * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:8:17: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int’ [-Wformat=]
    8 |         scanf("%d\n",w[i]);
      |                ~^    ~~~~
      |                 |     |
      |                 int * int
main.c:4:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    4 |         scanf("%d %d\n",&l,&n);
      |         ^~~~~~~~~~~~~~~~~~~~~~
main.c:8:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |         scanf("%d\n",w[i]);
      |         ^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
void main(void){
	int l = 0, n = 0;
	scanf("%d %d\n",&l,&n);
	int w[n];
    int i = 0;
    for(i = 0;i < n ; i++){
        scanf("%d\n",w[i]);
    }

    for(i = 0;i < n ; i++){
        for(int j = 0 ; j < n ; j++ ){
            if( w[i] > w[j] ){
                int sum = w[i];
                w[i] = w[j];
                w[j] = sum;
            }
        }
    }
    
    for(i = 0;i < n;i++){
        l = l - w[i];
        if(l <= 0){
            break;
        }
    }

    printf("%d",i);

}
0