#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> #pragma warning(disable:4996) #define max 100 bool is_ask_day1_weight(char*, int*); void analyze_turnips(char*, int*, int*); //分析蘿蔔字串 void clear_string(char*); bool weight_gain_and_loss(int*, int*, int*, int*, int*, int*, int*, int*, char*); bool is_die(int*); int main(void) { int test = 0, x = 0, y = 0, z = 0, w = 0, n = 0, m = 0, turnips[max] = { 0 }, turnips_number = 0; char days[max] = { '\0' }; scanf("%d", &test); getchar(); for (int i = 0; i < test; i++) { scanf("%d %d %d %d %d %d", &x, &y, &z, &w, &n, &m); getchar(); gets(days); if (is_ask_day1_weight(&days[0], &m)) { continue; } else { analyze_turnips(&days[0], &turnips[0], &turnips_number); if (weight_gain_and_loss(&x, &y, &z, &w, &n, &m, turnips, &turnips_number, days)) { printf("%dg\n", m); } } } return 0; } bool is_ask_day1_weight(char* days, int* m) { if (days[0] == '\0') { printf("%d\n", *m); return true; } else { return false; } } void analyze_turnips(char* days, int* turnips, int* turnips_number) { char register1[max] = { '\0' }; int i = 0, j = 0; while (i != strlen(days) + 1) { if (days[i] == ' ' || days[i] == '\0') { turnips[*turnips_number] = atoi(register1); (*turnips_number)++; clear_string(®ister1[0]); j = 0; } else { register1[j] = days[i]; j++; } i++; } } void clear_string(char* str) { for (int i = 0; i < max; i++) { str[i] = '\0'; } } bool weight_gain_and_loss(int* x, int* y, int* z, int* w, int* n, int* m, int* turnips, int* turnips_number, char* days) { int poisoning[max] = { 0 }, counter = 0, j = 0; for (int i = 0; i < *turnips_number; i++) { j = 0; //早上:中毒 while (poisoning[j] != 0) { *m -= *n; j++; } if (is_die(m)) { return false; } //晚上:吃蘿蔔 switch (turnips[i]) { case 0: break; case 1: *m += *x; break; case 2: *m += *y; break; case 3: *m -= *z; break; case 4: *m -= *w; poisoning[counter] = 1; counter++; break; } if (is_die(m)) { return false; } } return true; } bool is_die(int* m) { if (*m <= 0) { printf("bye~Rabbit\n"); return true; } else { return false; } }
#include #include #include #include #pragma warning(disable:4996) #define max 100 bool is_ask_day1_weight(char*, int*); void analyze_turnips(char*, int*, int*); //分析蘿蔔字串 void clear_string(char*); bool weight_gain_and_loss(int*, int*, int*, int*, int*, int*, int*, int*, char*); bool is_die(int*); int main(void) { int test = 0, x = 0, y = 0, z = 0, w = 0, n = 0, m = 0, turnips[max] = { 0 }, turnips_number = 0; char days[max] = { '\0' }; scanf("%d", &test); getchar(); for (int i = 0; i < test; i++) { scanf("%d %d %d %d %d %d", &x, &y, &z, &w, &n, &m); getchar(); gets(days); if (is_ask_day1_weight(&days[0], &m)) { continue; } else { analyze_turnips(&days[0], &turnips[0], &turnips_number); if (weight_gain_and_loss(&x, &y, &z, &w, &n, &m, turnips, &turnips_number, days)) { printf("%dg\n", m); } } } return 0; } bool is_ask_day1_weight(char* days, int* m) { if (days[0] == '\0') { printf("%d\n", *m); return true; } else { return false; } } void analyze_turnips(char* days, int* turnips, int* turnips_number) { char register1[max] = { '\0' }; int i = 0, j = 0; while (i != strlen(days) + 1) { if (days[i] == ' ' || days[i] == '\0') { turnips[*turnips_number] = atoi(register1); (*turnips_number)++; clear_string(®ister1[0]); j = 0; } else { register1[j] = days[i]; j++; } i++; } } void clear_string(char* str) { for (int i = 0; i < max; i++) { str[i] = '\0'; } } bool weight_gain_and_loss(int* x, int* y, int* z, int* w, int* n, int* m, int* turnips, int* turnips_number, char* days) { int poisoning[max] = { 0 }, counter = 0, j = 0; for (int i = 0; i < *turnips_number; i++) { j = 0; //早上:中毒 while (poisoning[j] != 0) { *m -= *n; j++; } if (is_die(m)) { return false; } //晚上:吃蘿蔔 switch (turnips[i]) { case 0: break; case 1: *m += *x; break; case 2: *m += *y; break; case 3: *m -= *z; break; case 4: *m -= *w; poisoning[counter] = 1; counter++; break; } if (is_die(m)) { return false; } } return true; } bool is_die(int* m) { if (*m <= 0) { printf("bye~Rabbit\n"); return true; } else { return false; } }
簡單