枚举分析
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
char Left[3][7];
char Right[3][7];
char Result[3][7];
bool IsFake(char,bool);//返回值为真表示是一枚假币,另一个参数代表比真币重还是轻
int main(){int t;cin >> t;while(t--){for(int i = 0;i < 3; ++i)cin >> Left[i] >> Right[i] >> Result[i];for(char c = 'A';c <= 'L'; ++c){if(IsFake(c,true))printf("%c is the counterfeit coin and it is light.n",c);else if(IsFake(c,false))printf("%c is the counterfeit coin and it is heavy.n",c);}}return 0;
}
bool IsFake(char c,bool light){//light为真表示假币比真币轻 for(int i = 0;i < 3; ++i){char *pLeft,*pRight;if(light == true){pLeft = Left[i];pRight = Right[i]; }else if(light == false){//换位置免去多余比较代码pLeft = Right[i];pRight = Left[i]; }switch(Result[i][0]){case 'u':if(strchr(pRight,c) == NULL)return false;break;case 'e':if(strchr(pLeft,c) || strchr(pRight,c))return false;break;case 'd':if(strchr(pLeft,c) == NULL)return false;break;}}return true;
}
本文发布于:2024-01-31 19:30:49,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170670065230836.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |