MOOC程序设计与算法练习题——枚举#2692假币问题

阅读: 评论:0

MOOC程序设计与算法练习题——枚举#2692假币问题

MOOC程序设计与算法练习题——枚举#2692假币问题

枚举——2692假币问题

枚举分析

#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小时内删除。

标签:练习题   假币   程序设计   算法   MOOC
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23