POJ1013(模拟题)
来源:互联网 发布:淘宝上挑三捡四的人 编辑:程序博客网 时间:2024/06/06 07:19
Total Submissions: 47575 Accepted: 15049
Description
Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are true silver dollars; one coin is counterfeit even though its color and size make it indistinguishable from the real silver dollars. The counterfeit coin has a different weight from the other coins but Sally does not know if it is heavier or lighter than the real coins.
Happily, Sally has a friend who loans her a very accurate balance scale. The friend will permit Sally three weighings to find the counterfeit coin. For instance, if Sally weighs two coins against each other and the scales balance then she knows these two coins are true. Now if Sally weighs
one of the true coins against a third coin and the scales do not balance then Sally knows the third coin is counterfeit and she can tell whether it is light or heavy depending on whether the balance on which it is placed goes up or down, respectively.
By choosing her weighings carefully, Sally is able to ensure that she will find the counterfeit coin with exactly three weighings.
Happily, Sally has a friend who loans her a very accurate balance scale. The friend will permit Sally three weighings to find the counterfeit coin. For instance, if Sally weighs two coins against each other and the scales balance then she knows these two coins are true. Now if Sally weighs
one of the true coins against a third coin and the scales do not balance then Sally knows the third coin is counterfeit and she can tell whether it is light or heavy depending on whether the balance on which it is placed goes up or down, respectively.
By choosing her weighings carefully, Sally is able to ensure that she will find the counterfeit coin with exactly three weighings.
Input
The first line of input is an integer n (n > 0) specifying the number of cases to follow. Each case consists of three lines of input, one for each weighing. Sally has identified each of the coins with the letters A--L. Information on a weighing will be given by two strings of letters and then one of the words ``up'', ``down'', or ``even''. The first string of letters will represent the coins on the left balance; the second string, the coins on the right balance. (Sally will always place the same number of coins on the right balance as on the left balance.) The word in the third position will tell whether the right side of the balance goes up, down, or remains even.
Output
For each case, the output will identify the counterfeit coin by its letter and tell whether it is heavy or light. The solution will always be uniquely determined.
Sample Input
1 ABCD EFGH even ABCI EFJK up ABIJ EFGH even
Sample Output
K is the counterfeit coin and it is light.
AC代码:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;char Left[3][7];char Right[3][7];char Result[3][7];bool IsLight(char);bool IsHeavy(char);int main(){ int n,i; char c; scanf("%d",&n); while(n--) { for(i=0; i<3; i++) { scanf("%s %s %s",Left[i],Right[i],Result[i]); } for(c='A'; c<='L'; c++) { if(IsLight(c)) { printf("%c is the counterfeit coin and it is light.\n",c); break; } if(IsHeavy(c)) { printf("%c is the counterfeit coin and it is heavy.\n",c); break; } } } return 0;}bool IsLight(char c){ int i; for(i=0; i<3; i++) { if(strchr(Left[i],c)!=NULL) { if(strcmp(Result[i],"down")!=0) { return false; } } else if(strchr(Right[i],c)!=NULL) { if(strcmp(Result[i],"up")!=0) { return false; } } else { if(strcmp(Result[i],"even")!=0) { return false; } } } return true;}bool IsHeavy(char c){ int i; for(i=0; i<3; i++) { if(strchr(Left[i],c)!=NULL) { if(strcmp(Result[i],"up")!=0) { return false; } } else if(strchr(Right[i],c)!=NULL) { if(strcmp(Result[i],"down")!=0) { return false; } } else { if(strcmp(Result[i],"even")!=0) { return false; } } } return true;}get新知识:strchr是计算机的一个函数,原型为extern char *strchr(const char *s,char c),可以查找字符串s中首次出现字符c的位置。
阅读全文
0 0
- POJ1013(模拟题)
- poj1013 模拟
- poj1013 模拟
- POJ1013-水模拟-Counterfeit Dollar
- POJ1013
- POJ1013
- POJ1013
- POJ1013
- poj1013
- poj1013
- poj1013
- poj1013
- poj1013
- poj1013
- poj1013-Counterfeit Dollar(简单逻辑题)
- 刷题打卡1 poj1543 ,poj1006,poj1013
- 枚举—案例(称硬币poj1013)
- Counterfeit Dollar HDU1482题 FZU1003题 POJ1013题
- Java 标准 I/O 流编程一览笔录( 下 )
- [转]Linux任务前后台的切换
- 【Java】把字节数B转化为KB、MB、GB的两种方法
- 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
- 贪心、回溯、穷举、分治、递归
- POJ1013(模拟题)
- [BZOJ]1370 Gang团伙 镜像并查集
- 植物大战僵尸2 转基因实验室在哪
- JS实现复制到剪贴板功能,兼容所有浏览器
- shell脚本 自动搭建ftp服务
- IntelliJ Idea 常用快捷键列表
- 实现一个函数,将一个字符串中的空格替换成“ ”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We Are Happy
- Shopping Offers问题及解法
- 连接数据库语句