結果

問題 No.5 数字のブロック
ユーザー ReERishun
提出日時 2019-06-05 10:13:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,203 bytes
コンパイル時間 134 ms
コンパイル使用メモリ 30,080 KB
最終ジャッジ日時 2025-01-07 04:15:25
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25 WA * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |     scanf("%d",&boxWidth);  //箱の高さ取得
      |     ~~~~~^~~~~~~~~~~~~~~~
main.cpp:14:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |     scanf("%d",&num);       //ブロックの個数取得
      |     ~~~~~^~~~~~~~~~~

ソースコード

diff #

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

int 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;
}
0