




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选优质文档-倾情为你奉上十二硬币判别代码 人间客制作国外流行的12个硬币问题:12硬币中可能有一个假的,而且不知道假币比真币重还是轻,给你一架天平,天平没有示数,只能判断是平衡还是不平,且只准称三次,让你判断是否有假币;如果有,找出来。解法思想如下:第一步:任选8个比较,如选: 比 一、若一样重,则假币在中,第二步: 比1.若一样重,则可能的假币为。则第三步: vs 1)若一样重,则没有假币;2)不一样重,则假币为:如果(1)>(12),则假币轻,反之,假币重; 2.若重,则第三步: 比 1)若一样重,则假币为(较轻)2)不一样重,则假币为、中较重者3.若轻,则第三步: 比 1)若一样
2、重,则假币为(较重)2)不一样重,则假币为、中较轻者二、若重,则第二步: 比 1.若一样重,则假币在中,第三步: 比 假币为、中较轻者2.若端较重,则假币在中,第三步:比 1)若一样重,则假币为(较轻)2)不一样重,则假币为中较重者3.若端较重,则假币在中,第三步: 比 1)若一样重,则假币为(较轻)2)不一样重,则假币为、中较重者三、若轻,则与上面类似,第二步:比 1.若一样重,则假币在中,第三步: 比 假币为、中较重者2.若端较轻,则假币在中,第三步: 比 1)若一样重,则假币为(较重)2)不一样重,则假币为中较轻者3.若端较轻,则假币在中,第三步: 比 1)若一样重,则假币为(较重)2)
3、不一样重,则假币为、中较轻者在科技发达的时代,我们都不愿意去做这样繁琐的比较,而是想借助于计算机的威力,下面给大家介绍一种方法,可以在很短的时间内完成中比较。当然,这类问题转化到编程上去后,主要考查的是大家的编程思想,而不再是12硬币问题本身了,因为12个硬币的重量需要大家自己去输入,这些数据只是为了检验大家程序的正确与否。下面是该问题的代码:#include <stdio.h>void main()int i;float a12;for(i=0;i<12;i+)scanf("%f",&ai);if(a0+a1+a2+a3=a4+a5+a6+a7)
4、 if(a0+a1+a2=a8+a9+a10) if(a8=a11) printf("There is no special coin!n"); else if(a8>a11) printf("There is a special coin:%f(12) and it's lighter than others.n",a11); else printf("There is a special coin:%f(12) and it's heavier than others.n",a11); else if(a0+
5、a1+a2>a8+a9+a10) if(a8=a9) printf("There is a special coin:%f(11) and it's lighter than others.n",a10); else if(a8>a9) printf("There is a special coin:%f(10) and it's lighter than others.n",a9); else printf("There is a special coin:%f(9) and it's lighter th
6、an others.n",a8); else if(a8=a9) printf("There is a special coin:%f(11) and it's heavier than others.n",a10); else if(a8>a9) printf("There is a special coin:%f(9) and it's heavier than others.n",a8); else printf("There is a special coin:%f(10) and it's he
7、avier than others.n",a9); else if(a0+a1+a2+a3>a4+a5+a6+a7) if(a0+a2+a5=a1+a4+a8) if(a6=a7) printf("There is a special coin:%f(4) and it's heavier than others.n",a3); else if(a6>a7) printf("There is a special coin:%f(8) and it's lighter than others.n",a7); else
8、printf("There is a special coin:%f(7) and it's lighter than others.n",a6); else if(a0+a2+a5>a1+a4+a8) if(a0=a2) printf("There is a special coin:%f(5) and it's lighter than others.n",a4); else if(a0>a2) printf("There is a special coin:%f(1) and it's heavier
9、than others.n",a0); else printf("There is a special coin:%f(3) and it's heavier than others.n",a2); else if(a1>a8) printf("There is a special coin:%f(2) and it's heavier than others.n",a1); if(a5<a8) printf("There is a special coin:%f(6) and it's light
10、er than others.n",a5); else if(a0+a2+a5=a1+a4+a8) if(a6=a7) printf("There is a special coin:%f(4) and it's lighter than others.n",a3); else if(a6>a7) printf("There is a special coin:%f(7) and it's heavier than others.n",a6); else printf("There is a special co
11、in:%f(8) and it's heavier than others.n",a7); else if(a0+a2+a5<a1+a4+a8) if(a0=a2) printf("There is a special coin:%f(5) and it's heavier than others.n",a4); else if(a0>a2) printf("There is a special coin:%f(3) and it's lighter than others.n",a2); else printf("There is a special coin:%f(1) and it's lighter than others.n",a0); else if(a1<a8) printf("There is a spe
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 医院物业保安服务合同范例
- 保险正规合同范例
- 包车客运服务合同范例
- 做煤炭合同范例
- 北京合同范本
- 冷饮配送转让合同范例
- fidic 商务合同范例
- 制冷配件销售合同范例
- 协办单位合作合同范本
- 冰品购销合同范例
- 统编版(2024)道德与法治七年级下册第一单元 珍惜青春时光 单元测试卷(含答案)
- 儿童各年龄期保健儿童保健学课件
- 苏教版数学一年级下册(2024)第七单元观察物体(一)综合素养测评 A 卷(含答案)
- 2025年中考英语第一次模拟试卷01(广州专用)(原卷版)
- 2025年甘肃省张掖市民乐县招聘专业技术人员9人(第二期)历年高频重点模拟试卷提升(共500题附带答案详解)
- 2025年湖北武汉理工大学学生辅导员招聘18人历年高频重点模拟试卷提升(共500题附带答案详解)
- 《石油工程事故案例分析》课件
- 金融科技概论-课件 第十五章 金融科技监管与监管科技
- 初级咖啡师资格理论考试题及答案
- 2025年乌兰察布医学高等专科学校高职单招职业技能测试近5年常考版参考题库含答案解析
- 招标代理机构选取突发情况应急处理预案
评论
0/150
提交评论