poj 1013
来源:互联网 发布:手机淘宝差评改好评 编辑:程序博客网 时间:2024/05/16 07:15
//
解题思路:
总体就是枚举的思路,因为题目中规定了是A-L的12个字符,我们就枚举A-L,对于枚举的每一个字符c,也就是c是假币有两个情况,c是轻的假币或者, c是重的假币。
以上我们可以写出for(char c = A ~ L),然后我们用IsFake()函数来判断,注意IsFake()中的light 参数,如果light == true表示验证c是假的轻币的可能,如果light == false表示验证c是假的重币的可能。
strchar(str,’c’) == null 表示c不在str中。
#include <iostream>#include <cstring>#include <cstdlib>using namespace std;char Left[3][7];char Right[3][7];char Result[3][7];bool IsFake(char c, bool light){ //light 为真表示假币为轻,否则表示表示假币为重 for(int i = 0; i < 3; i++){ char *pLeft, *pRight;//指向天平两边的字符串 if(light) { pLeft = Left[i]; pRight = Right[i]; } else {//如果假设硬币是重的,则把称量左右交换,就是main中 else IsFake(...)那种 pLeft = Right[i]; pRight = Left[i]; } //对每个c进行三组的比较,如果三组result都满足,则最后return true,表示此时的c是真的假币 switch(Result[i][0]) {//天平右边的情况 case 'u'://up表示c在右边. if(strchr(pRight,c) == NULL)//如果c不在右边 return false; break; case 'e': if(strchr(pLeft,c) || strchr(pRight,c))//如果轻的c在左边或者右边但是是"even"天平右边的情况 return false; break; case 'd':if(strchr(pLeft,c) == NULL)//如果c不在左边 return false; break; } } return true;}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)) { cout << c << " is the counterfeit coin and it is light." << endl; break; } else if(IsFake(c,false)) { cout << c << " is the counterfeit coin and it is heavy." << endl; break; } } } // system("pause"); return 0;}
0 0
- POJ 1013
- Poj 1013
- poj 1013
- POJ 1013
- POJ-1013
- POJ 1013
- poj 1013
- poj 1013
- poj-1013
- poj 1013
- poj 1013 && poj 1029【寻找硬币】
- POJ 1013 Counterfeit Dollar
- POJ 1013 Counterfeit Dollar
- hdoj 1482 poj 1013
- POJ 1013 Counterfeit Dollar
- POJ 1013 Counterfeit Dollar
- POJ 1013 Counterfeit Dollar
- POJ 1013 称硬币
- 1st round, 161 One Edit Distance
- CKeditor配置
- java基础之static关键字作用
- 机器学习CART及CCP剪枝原理
- 自定义标签模板
- poj 1013
- css交集选择器、并集选择器、兄弟选择器
- Springboot+Ebean配置Mysql数据源报错
- 洛谷P1223 排队接水
- Python函数的参数
- 微信小程序之wx.request:fail错误,真机预览请求无效问题解决,安卓,ios网络预览异常
- Android 编译提速
- Java线程池架构原理和源码解析(ThreadPoolExecutor)
- Redis学习笔记