#12522: 自己跑測資有過,但測試執行卻沒過?


andy94077 (Grunwald)

學校 : 國立臺灣大學
編號 : 53812
來源 : [203.73.205.80]
最後登入時間 :
2019-04-07 22:51:39
a271. 彩色蘿蔔 -- 兔子 | From: [175.180.71.232] | 發表日期 : 2017-08-06 12:10

明明自己跑都成功1g,但測試執行時他卻說我是bye~Rabbit?

另外,我解題也一直NA,一直找不出原因,請各位大大解答

 

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
int carrot[5] = { 0 };// 空,紅, 白, 黃, 黑
int times, poison,accumulated_poison, weight;
int read_carrot;
stringstream ss("");
string str;
cin >> times;
for (int i = 0; i < times; i++)
{
ss.str("");
ss.clear();
accumulated_poison = 0;

cin >> carrot[1] >> carrot[2] >> carrot[3] >> carrot[4] >> poison >> weight;
carrot[3] *= -1;
carrot[4] *= -1;

//上一行還有enter鍵還沒讀,所以要先清掉enter,再讀下一行
getline(cin, str);
getline(cin, str);
ss << str;
while (!ss.eof() && (weight -= accumulated_poison)>0 && str!="")
{
ss >> read_carrot;
weight += carrot[read_carrot];
if (read_carrot == 4)
accumulated_poison += poison;
}
(weight <= 0) ? (cout << "bye~Rabbit") : (cout << weight<<'g');
cout << endl;
}
return 0;
}

 

 
#13628: Re:自己跑測資有過,但測試執行卻沒過?


snakeneedy (蛇~Snake)

學校 : 國立高雄師範大學附屬高級中學
編號 : 7661
來源 : [114.40.8.251]
最後登入時間 :
2023-01-25 19:16:06
a271. 彩色蘿蔔 -- 兔子 | From: [218.164.125.30] | 發表日期 : 2018-03-31 02:48

明明自己跑都成功1g,但測試執行時他卻說我是bye~Rabbit?

另外,我解題也一直NA,一直找不出原因,請各位大大解答

 

#include
#include
#include
using namespace std;

int main()
{
int carrot[5] = { 0 };// 空,紅, 白, 黃, 黑
int times, poison,accumulated_poison, weight;
int read_carrot;
stringstream ss("");
string str;
cin >> times;
for (int i = 0; i < times; i++)
{
ss.str("");
ss.clear();
accumulated_poison = 0;

cin >> carrot[1] >> carrot[2] >> carrot[3] >> carrot[4] >> poison >> weight;
carrot[3] *= -1;
carrot[4] *= -1;

//上一行還有enter鍵還沒讀,所以要先清掉enter,再讀下一行
getline(cin, str);
getline(cin, str);
ss << str;
while (!ss.eof() && (weight -= accumulated_poison)>0 && str!="")
{
ss >> read_carrot;
weight += carrot[read_carrot];
if (read_carrot == 4)
accumulated_poison += poison;
}
(weight <= 0) ? (cout << "bye~Rabbit") : (cout << weight<<'g');
cout << endl;
}
return 0;
}

 


while 的部份改成

while (ss >> read_carrot)
{
    if ((weight -= accumulated_poison) <= 0) break;
    weight += carrot[read_carrot];
    if (read_carrot == 4) accumulated_poison += poison;
}

就可以過測試了

 
ZeroJudge Forum