编程题目求解3

来源:百度知道 编辑:UC知道 时间:2024/06/06 13:05:51
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 ensur

#include<iostream.h>
#include<string.h>
char a[3][16],b[3][16],c[3][5];
int checkheavy(int i)
{
int j=0,k,l,exist;
for(l=0;l<3;l++)
{
exist=0;
for(k=0;k<16;k++)
{
if (a[l][k]==' ')break;
if (a[l][k]==i+65)
{
exist=1;
if (strcmp(c[l],"up")!=0){return 0;}
else j=1;
}
if (b[l][k]==i+65)
{
exist=1;
if (strcmp(c[l],"down")!=0){return 0;}
else j=1;
}
}
if(j==1&&exist==0&&strcmp(c[l],"even")!=0)return 0;
}
return j;
}
int checklight(int i)
{
int j=0,k,l,exist;
for(l=0;l<3;l++)
{
exist=0;
for(k=0;k<16;k++)
{
if (a[l][k]==' ')break;
if (a[l][k]==i+65)