結果
問題 | No.842 初詣 |
ユーザー |
![]() |
提出日時 | 2019-07-02 17:11:31 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 1,766 bytes |
コンパイル時間 | 392 ms |
コンパイル使用メモリ | 29,440 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-13 06:34:38 |
合計ジャッジ時間 | 1,037 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include<stdio.h>#include<stdlib.h>#define STR_LENGTH 23#define NUM_INPUT 7#define OK 1#define NO -1const 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; //配列NOint 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;}