详细题目见PTA,就过了两组测试数据,大佬路过可以帮忙找找bug~
#include<iostream>
using namespace std;
int temp[5];
int saveA=0, saveB=0;
bool check(int a, int b, int echo);
int main()
{
int a, b;
int echo;
cin >> a >> b;
cin >> echo;
bool who = check(a, b, echo);
if(who){
cout << "A" << endl;
cout << saveB;
}else{
cout << "B" << endl;
cout << saveA;
}
}
bool check(int a, int b, int echo)
{
while (echo--)
{
for (int i = 1; i <= 4; i++)
{
cin >> temp[i];
}
if (temp[1] + temp[3] == temp[2] && temp[2] != temp[3])
{
a -= 1;
saveA++;
}
else if (temp[1] + temp[3] == temp[3] && temp[2] != temp[3])
{
b -= 1;
saveB++;
}
if (a == 0)
return true;
else if (b == 0)
return false;
}
}
感谢博主Whisper_yl的帮助,下面更新这道题的正确方法
#include<iostream>
using namespace std;
int temp[5];
int saveA=0, saveB=0;
bool check(int a, int b, int echo);
int main()
{
int a, b;
int echo;
cin >> a >> b;
cin >> echo;
bool who = check(a, b, echo);
if(who){
cout << "A" << endl;
cout << saveB;
}else{
cout << "B" << endl;
cout << saveA;
}
}
bool check(int a, int b, int echo)
{
while (echo--)
{
for (int i = 1; i <= 4; i++)
{
cin >> temp[i];
}
if (temp[1] + temp[3] == temp[2] && temp[1] + temp[3] == temp[4])
continue;
if (temp[1] + temp[3] == temp[2])
{
a -= 1;
saveA++;
}
else if (temp[1] + temp[3] == temp[4])
{
b -= 1;
saveB++;
}
if (a == -1)
return true;
else if (b == -1)
return false;
}
}