a271.
彩色蘿蔔
--
兔子
| From: [140.118.74.187] |
發表日期
:
2023-10-25 15:27
#include <stdio.h>
int main() {
int times = 0;
scanf("%d", ×);
for (int i = 0; i < times; i++) {
//讀取資料
int weight[5] = { 0 }, decre = 0, ori_wei = 0;//中毒跟初始體重
char days_eat[1000] = {'\0'};
scanf("%d%d%d%d%d%d", &weight[1], &weight[2], &weight[3], &weight[4], &decre, &ori_wei);
char c = getchar(); //有迴車鍵
gets(days_eat);
//讀取資料結束
weight[3] = -weight[3]; //這個兩個是減重
weight[4] = -weight[4];
int count = 0; //用來記錄中毒層數
for (int i = 0; days_eat[i] != '\0'; i += 2) {
ori_wei -= decre * count; //中毒減重,先減
if (ori_wei <= 0){
printf("bye~Rabbit\n");
break;
}
ori_wei += weight[days_eat[i] - '0'];
if (days_eat[i] == '4') count++; //疊buff
if (ori_wei <= 0) {
printf("bye~Rabbit\n");
break;
}
}
if (ori_wei > 0) printf("%dg\n", ori_wei);
}
return 0;
}
這題花了我超多時間,原因出在gets和fgets,我原先用fgets(days_eat,1000,stdin),一直出問題,有大佬能夠告訴我為什麼嗎