結果

問題 No.5 数字のブロック
ユーザー KunihikoWada
提出日時 2016-09-30 15:57:12
言語 C90
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,080 bytes
コンパイル時間 591 ms
コンパイル使用メモリ 21,504 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-21 11:15:35
合計ジャッジ時間 2,304 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24 WA * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
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", &L);
      |     ^~~~~~~~~~~~~~~
main.c:8:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |     scanf("%d", &N);
      |     ^~~~~~~~~~~~~~~
main.c:12:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         scanf("%d ", &W[i]);
      |         ^~~~~~~~~~~~~~~~~~~

ソースコード

diff #

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

int main(void) {
    int L, N, i, j, k, temp, count, length;

    scanf("%d", &L);
    scanf("%d", &N);
    //printf("%d\n", N);
    int *W = malloc(sizeof(int) * N);
    for (i = 0; i < N; i++) {
        scanf("%d ", &W[i]);
        //printf("a\n");
    }
    /*for(i = 0; i < N; i++) {
        printf("%d ", W[i]);
    }*/
    //printf("bb\n");
    /*for (i = 0; i < N; N++) {
        printf("%d ", W[i]);
    }
    printf("\n");*/
    for (i = 0; i < N - 1; i++) {
        for (j = 0; j < N - i - 1; j++) {
            if (W[j] > W[j + 1]) {
                temp = W[j];
                W[j] = W[j + 1];
                W[j + 1] = temp;
            }
        }
        /*for (k = 0; k < N; k++) {
            printf("%d ", W[k]);
        }
        printf("\n");*/
    }
    /*printf("After Sorting\n");
    for (i = 0; i < N; i++) {
        printf("%d ", W[i]);
    }
    printf("\n");*/
    i = 0;
    length = 0;
    while ((N >= i) && ((length += W[i]) <= L)) {
        i++;
    }
    printf("%d\n", i);
    free(W);

    return 0;
}
0