/*问题描述:
设有8枚硬币a,b,c,d,e,f,g,h,其中有一枚硬币是伪造的。
真伪硬币的区别仅是重量不同,可能重,可能轻。今要求以天平为工具,用最少的
比较次数挑出伪造硬币,并鉴定它是重还是轻。
*/
//只是找出不标准的球,没有判别轻重,3次称量
- #include<iostream>
- using namespace std;
- int main(){
- int a,b,c,d,e,f,g,h;
- int count=0;//称量的次数
- cout<<"Please Enter the eight coins weight!"<<endl;
- cin>>a>>b>>c>>d>>e>>f>>g>>h;
- //进行称重判断
- if(a+b==c+d){//a,b,c,d都合格
- count++;
- if(a+b==e+f){//e,f也合格,则可推出g,h中必有一个不合格
- count++;
- if(a==g){//g合格,则h不合格,输出
- count++;
- cout<<"h is not check out!"<<endl;
- }
- else{
- count++;
- cout<<"g is not check out!"<<endl;
- }
- }
- else{//e,f中有一个不合格
- count++;
- if(a==e){
- count++;
- cout<<"f is not check out!"<<endl;
- }
- else{
- count++;
- cout<<"e is not check out!"<<endl;
- }
- }//end_else
- }//end_if
- else{//a,b,c,d中有不合格的,则可推出e,f,g,h都合格
- count++;
- if(a+b==e+f){//a,b合格,则c,d中有一个不合格
- count++;
- if(c==e){
- count++;
- cout<<"d is not check out!"<<endl;
- }
- else{
- count++;
- cout<<"c is not check out!"<<endl;
- }
- }
- else{//a,b中有不合格的
- if(a==e){
- count++;
- cout<<"b is not check out!"<<endl;
- }
- else{
- count++;
- cout<<"a is not check out!"<<endl;
- }
- }
- }
- cout<<count<<endl;
- return 0;
- }