1013
此题思想:枚举每个硬币是light or heavy,依次验证三个结果是否一致
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<string> lEnd, rEnd, result;
bool isLight(char x);
bool isHeavy(char x);
int main()
{
int cnt;
const string state(" is the counterfeit coin and it is ");
cin >> cnt;
while (cnt--) {
lEnd.clear();
rEnd.clear();
result.clear();
for (int i = 0; i < 3; ++i) {
string str;
cin >> str;
lEnd.push_back(str);
cin >> str;
rEnd.push_back(str);
cin >> str;
result.push_back(str);
}
for (char x = 'A'; x < 'M'; ++x) {
if (isLight(x)) {
cout << x << state << "light." << endl;
break;
}
else if (isHeavy(x)) {
cout << x << state << "heavy." << endl;
break;
}
}
}
return 0;
}
bool inLeft(int i, char x)
{
string str = lEnd[i];
for (size_t i = 0; i < str.size(); ++i)
if (x == str[i]) return true;
return false;
}
bool inRight(int i, char x)
{
string str = rEnd[i];
for (size_t i = 0; i < str.size(); ++i)
if (x == str[i]) return true;
return false;
}
bool isLight(char x)
{
int i;
string str;
for (i = 0; i < 3; ++i) {
str = result[i];
switch (str[0]) {
case 'd':
if (!inLeft(i, x)) return false;
break;
case 'e':
if (inRight(i, x) || inLeft(i, x)) return false;
break;
case 'u':
if (!inRight(i, x)) return false;
break;
}
}
return true;
}
bool isHeavy(char x)
{
int i;
string str;
for (i = 0; i < 3; ++i) {
str = result[i];
switch (str[0]) {
case 'd':
if (!inRight(i, x)) return false;
break;
case 'e':
if (inRight(i, x) || inLeft(i, x)) return false;
break;
case 'u':
if (!inLeft(i, x)) return false;
break;
}
}
return true;
}


浙公网安备 33010602011771号