結果

問題 No.842 初詣
ユーザー GinFizz1185GinFizz1185
提出日時 2019-07-02 17:11:31
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,766 bytes
コンパイル時間 1,445 ms
コンパイル使用メモリ 27,912 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-11 07:27:04
合計ジャッジ時間 1,591 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#define STR_LENGTH 23
#define NUM_INPUT 7
#define OK 1
#define NO -1

const static unsigned int coin_value[NUM_INPUT] = {500, 100, 50, 10, 5, 1};

void str_cut(char*, unsigned int*);
char judge_dating(unsigned int*);

int main(void){
  char judge_num = 0;
  char str[STR_LENGTH];
  unsigned int money[NUM_INPUT] = {0}; /* [0]:500エン玉の枚数 etc */

  fgets(str, sizeof(str), stdin);
  str_cut(str, money);

  judge_num = judge_dating(money);
  if(OK == judge_num){
    printf("YES\n");
  } else {
    printf("NO\n");
  }

  return 0;
}

/*
関数概要:渡された文字列を空白で分離し、数値に変換する
第1引数:文字列
第2引数:文字列から数値に変換して格納する配列
*/
void str_cut(char* str, unsigned int* money){
  int start_str = 0;
  int num = 0; //配列NO
  int i = 0;

  while('\0' != str[i]){
    if(' ' == str[i]){
      str[i] = '\0';
      money[num] = (unsigned int) atoi(&str[start_str]);
      ++num;
      ++i;
      start_str = i;
    }
    ++i;
  }

  money[num] = (unsigned int) atoi(&str[start_str]);

  return;
}

/*
関数概要:渡された数値(配列)からヤスオくんはモルガナ先輩と付き合えるか判断する
第1引数:各コインの枚数とお賽銭額の配列
戻り値:付き合える場合:OK, 付き合えない場合:NO
*/
char judge_dating(unsigned int* money){
  char ret = 0;
  unsigned int temp_money = 0;
  int i = 0;

  temp_money = money[6];

  while(i < (NUM_INPUT - 1)){
    if((temp_money >= coin_value[i]) && (money[i] > 0)){
      temp_money -= coin_value[i];
      money[i] -= 1;
    } else {
      i++;
    }
  }

  if(temp_money == 0){
    ret = OK;
  } else {
    ret = NO;
  }

  return ret;
}
0