結果
問題 | No.825 賢いお買い物 |
ユーザー |
![]() |
提出日時 | 2019-07-02 20:35:03 |
言語 | C (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,774 bytes |
コンパイル時間 | 372 ms |
コンパイル使用メモリ | 28,968 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-10-11 15:55:49 |
合計ジャッジ時間 | 1,797 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
ソースコード
#include<stdio.h> #include<stdlib.h> #define STR_LENGTH 10 #define NUM_INPUT 3 #define IMPOSSIBLE 255 void str_cut(char*, unsigned char*); unsigned char judge_fee(unsigned char*); unsigned char judge_area1(unsigned char*, char); unsigned char judge_area2(unsigned char*, char); unsigned char judge_area3(unsigned char*, char); unsigned char judge_area4(unsigned char*, char); int main(void){ unsigned char judge_num = 0; char str[STR_LENGTH]; unsigned char coin_num[NUM_INPUT] = {0}; /* [0]:1G玉の枚数 etc */ fgets(str, sizeof(str), stdin); str_cut(str, coin_num); judge_num = judge_fee(coin_num); if(IMPOSSIBLE != judge_num){ printf("%d\n", judge_num); } else { printf("Impossible\n"); } return 0; } /* 関数概要:渡された文字列を空白で分離し、数値に変換する 第1引数:文字列 第2引数:文字列から数値に変換して格納する配列 */ void str_cut(char* str, unsigned char* coin_num){ int start_str = 0; int num = 0; //配列NO int i = 0; while('\0' != str[i]){ if(' ' == str[i]){ str[i] = '\0'; coin_num[num] = (unsigned char) atoi(&str[start_str]); ++num; ++i; start_str = i; } ++i; } coin_num[num] = (unsigned char) atoi(&str[start_str]); for(int i=0; i<NUM_INPUT;i++){ printf("coin_num[%d] = %d\n", i, coin_num[i]); } return; } /* 関数概要:渡された数値から買い物金額を計算する 第1引数:与えられた数値 戻り値:支払うべき料金(255はimpossible) */ unsigned char judge_fee(unsigned char* coin_num){ char use_coin = 0; unsigned char ret = 0; use_coin = coin_num[0] + coin_num[1] - coin_num[2]; if(use_coin < -8){ ret = judge_area1(coin_num, use_coin); } else if((-8 <= use_coin) &&(use_coin < 0)){ ret = judge_area2(coin_num, use_coin); } else if((0 <= use_coin) &&(use_coin < 10)){ ret = judge_area3(coin_num, use_coin); } else { ret = judge_area4(coin_num, use_coin); } return ret; } unsigned char judge_area1(unsigned char* coin_num, char use_coin){ return IMPOSSIBLE; } unsigned char judge_area2(unsigned char* coin_num, char use_coin){ unsigned char ret = 0; if(0 == coin_num[1]){ ret = IMPOSSIBLE; } else { ret = 9 + use_coin; } return ret; } unsigned char judge_area3(unsigned char* coin_num, char use_coin){ unsigned char ret = 0; if(coin_num[0] >= use_coin){ ret = use_coin; } else { ret = coin_num[0] + 10 * (use_coin - coin_num[0]); } return ret; } unsigned char judge_area4(unsigned char* coin_num, char use_coin){ unsigned char ret = 0; if(coin_num[0] >= (use_coin + 1)){ ret = use_coin - 9; } else { ret = coin_num[0] + 10 * (use_coin - coin_num[0]); } return ret; }