結果
問題 | No.825 賢いお買い物 |
ユーザー | GinFizz1185 |
提出日時 | 2019-07-02 20:37:59 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 2,694 bytes |
コンパイル時間 | 608 ms |
コンパイル使用メモリ | 29,952 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-13 14:44:07 |
合計ジャッジ時間 | 1,376 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 1 ms
6,944 KB |
testcase_11 | AC | 1 ms
6,944 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,940 KB |
testcase_14 | AC | 1 ms
6,940 KB |
testcase_15 | AC | 1 ms
6,940 KB |
testcase_16 | AC | 1 ms
6,940 KB |
testcase_17 | AC | 1 ms
6,940 KB |
testcase_18 | AC | 1 ms
6,940 KB |
testcase_19 | AC | 1 ms
6,944 KB |
testcase_20 | AC | 1 ms
6,940 KB |
testcase_21 | AC | 1 ms
6,940 KB |
ソースコード
#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]); 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; }