結果

問題 No.5 数字のブロック
コンテスト
ユーザー ree-rishun
提出日時 2019-06-05 10:10:08
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
RE  
実行時間 -
コード長 1,210 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 159 ms
コンパイル使用メモリ 39,272 KB
最終ジャッジ日時 2026-02-22 03:32:28
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other RE * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

void main() {

    //箱の高さ
    int boxWidth=0;

    //ブロック個数
    int num=0;


    scanf("%d",&boxWidth);  //箱の高さ取得
    scanf("%d",&num);       //ブロックの個数取得

    int width[num+1];

    //初期化
    for(int i=0;i<num+1;i++)
        width[i]=0;

    //入力判定
    for(int i=0;i<num+1;i++){
        char numBox;
        for(int j=0;;j++){
            numBox = getchar();
            if(numBox < '0'||numBox > '9')
                break;
            else
                width[i] = width[i] * 10 + (int)numBox - (int)'0';
        }
    }

    //配列先頭の空白削除
    for(int i=0;i<num+1;i++)
        width[i]=width[i+1];

    //昇順にソート
    for(int i=0;i<num-1;i++){
        int numBox;
        for(int j=0;j<num-1;j++){
            if(width[j]>width[j+1]){
                numBox = width[j];
                width[j] = width[j+1];
                width[j+1] = numBox;
            }

        }
    }
    
    //答え格納変数
    int ans=0;
    
    //箱に格納
    for(;boxWidth > width[ans];ans++){
        boxWidth -= width[ans];
    }

    //出力
    printf("%d\n",ans);


    return;
}
0