輸入執行次數
迴圈
輸入數據
依題目所述執行
判別血量
>0
輸出體重
<0
輸出字串
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
using namespace std;
void setData(int carrot[], int *hp, int *toxic_hp, int *toxic_times, string *eat);
int main()
{
int times;
int carrot[4];
int hp;
int toxic_hp, toxic_times;
string eat;
stringstream ss;
int carrot_id;
while(cin >> times)
{
while(times--)
{
setData(carrot, &hp, &toxic_hp, &toxic_times, &eat);
ss.str("");
ss.clear();
ss.str(eat);
while(ss >> carrot_id)
{
hp -= toxic_hp*toxic_times;
if(hp <= 0)
break;
switch(carrot_id)
{
case 1: hp += carrot[0];
break;
case 2: hp += carrot[1];
break;
case 3: hp -= carrot[2];
break;
case 4: hp -= carrot[3]; toxic_times++;
break;
default:
break;
}
}
if(hp > 0)
cout << hp << "g\n";
else
cout << "bye~Rabbit\n";
}
}
return 0;
}
void setData(int carrot[], int *hp, int *toxic_hp, int *toxic_times, string *eat)
{
for(int i = 0; i<4; i++)
cin >> carrot[i];
cin >> *toxic_hp >> *hp;
getchar();
getline(cin, *eat);
*toxic_times = 0;
}
留言列表