結果

問題 No.5 数字のブロック
ユーザー yfujita0929yfujita0929
提出日時 2016-04-10 14:05:39
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,678 bytes
コンパイル時間 125 ms
コンパイル使用メモリ 22,400 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 23:47:17
合計ジャッジ時間 2,968 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 WA -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 WA -
testcase_15 WA -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 RE -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:16:5: warning: ignoring return value of ‘fgets’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |     fgets(str, STR_SIZE, stdin);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:19:5: warning: ignoring return value of ‘fgets’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |     fgets(str, STR_SIZE, stdin);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:23:5: warning: ignoring return value of ‘fgets’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |     fgets(str, STR_SIZE, stdin);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

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

#define STR_SIZE 10000

void sortArr(int *arr, int arr_size);
void swap(int *x, int *y);
int simulation(int size, int *arr, int arr_size);

int main(void){
    char *str, *token;
    int box_size, block_num, *block_wid_arr, idx, result;

    str = (char*)calloc(sizeof(char), STR_SIZE);
    fgets(str, STR_SIZE, stdin);
    box_size = atoi(str);

    fgets(str, STR_SIZE, stdin);
    block_num = atoi(str);

    block_wid_arr = (int*)calloc(sizeof(int), block_num);
    fgets(str, STR_SIZE, stdin);
    token = strtok(str, " ");
    for(idx = 0; idx < block_num; idx++) {
        block_wid_arr[idx] = atoi(token);
        token = strtok(NULL, " ");
    }
    
    sortArr(block_wid_arr, block_num);

    /*
    for(idx = 0; idx < block_num; idx++) {
        printf("%d ", block_wid_arr[idx]);
    }
    */
    
    result = simulation(box_size, block_wid_arr, block_num);
    
    printf("\n%d", result);

    free(str);
    free(block_wid_arr);
    
    return 0;
}

void sortArr(int *bw_arr, int arr_size)
{
    int tmp, i, j;
    int min;
    
    for(i = 0; i < arr_size; i++) {
        min = 10001;
        for(j = i; j < arr_size; j++) {
            if(bw_arr[j] < min) {
                min = bw_arr[j];
                
                swap(&bw_arr[i], &bw_arr[j]);
            }
        }
    }
}

void swap(int *x, int *y) {
    int tmp;
    
    tmp = *x;
    *x = *y;
    *y = tmp;
}

int simulation(int bs, int *bl_arr, int bls) {
    int i, ret = 0;
    
    for(i = 0; i < bls; i++) {
        bs -= bl_arr[i];
        if(bs < 0) {
            break;
        }
        ret++;
    }
    
    return ret;
}
0