結果

問題 No.143 豆
ユーザー ReERishunReERishun
提出日時 2019-06-05 22:18:36
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 878 bytes
コンパイル時間 1,054 ms
コンパイル使用メモリ 28,372 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 17:33:44
合計ジャッジ時間 1,951 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 0 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 0 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 0 ms
4,376 KB
testcase_15 AC 0 ms
4,376 KB
testcase_16 AC 0 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main() {

    int beans;
    int package;
    int familly;
    scanf("%d %d %d",&beans,&package,&familly);

    int yOld[familly+1];

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

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

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

    //豆粒の数計算
    beans *= package;

    //年齢合計
    for(int i=1;i<familly;i++)
        yOld[0]+=yOld[i];

    //結果出力
    if(yOld[0]>beans){
        printf("-1");
    }else{
        printf("%d",beans-yOld[0]);
    }

    return 0;
}
0