下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 山东省菏泽市高二上学期期中考试地理试题(B)
- 2025年新能源行业企业数字化转型中的能源调度与优化数据应用报告
- 2026广东中山市委党校招聘事业单位人员2人笔试考试备考题库及答案解析
- 2025福建厦门市集美区侨英小学非在编教师招聘1人考试笔试参考题库附答案解析
- 《JBT10257-2001 电阻焊设备 - 用于电极挡块的绝缘销》(2026年)实施指南
- 《JBT10074-2004 电阻真空计技术条件》(2026年)实施指南
- 《JBT9900.2-1999 卧式精镗床镗头技术条件》(2026年)实施指南
- 2025秋季贵州黔西南州兴仁市事业单位赴省内外高校引进高层次和急需紧缺人才13人考试笔试备考试题及答案解析
- 2026广东茂名市电白区医疗卫生单位赴广州中医药大学大学城校区现场招聘医务人员83人(编制)笔试考试参考题库及答案解析
- 肺胀慢性阻塞性肺疾病稳定期健康教育与康复指导
- 脑出血知识培训课件
- 2025年美妆行业消费者购买行为研究报告
- 2025国家应急管理部所属单位第二批次招聘1人模拟试卷及一套参考答案详解
- 2025年共青团团课考试题库(含答案)
- HPV疫苗知识培训课件
- 电厂防寒防冻安全培训课件
- 精益8大浪费课件
- 2025年湖北省生态环保有限公司招聘33人笔试参考题库附带答案详解
- 乡镇避孕药具培训课件
- 奶牛场疫病净化工作汇报
- 水利监理人员安全培训课件
评论
0/150
提交评论