




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025江西吉安市青原区两山发展集团有限公司部分岗位任职要求调整笔试模拟及1套完整答案详解
- 《三级医院评审标准(2025年版)》要点解读及培训
- 教师招聘之《小学教师招聘》模拟卷包附完整答案详解(网校专用)
- 2023年呼伦贝尔农垦谢尔塔拉特泥河哈达图浩特陶海农牧场招聘172人笔试历年难、易错考点及答案详解(必刷)
- 2025年教育游戏化在小学英语阅读教学中的应用与教学设计
- 2025年物流与供应链行业智能制造发展趋势研究
- 2025年环境影响评价公众参与机制在环境教育创新中的应用报告
- 合并2型糖尿病的激素依赖型乳腺癌:临床特征、预后及潜在机制探究
- 公司委托代理服务合同3篇
- 基于2025年的基层医疗卫生服务体系改革与基层医疗机构服务能力评价体系研究
- 《现代供电技术》课件(共八章)
- 2025年公共设施管理行业研究报告及未来发展趋势预测
- 高一语文学法指导(绝对经典)
- 双胎妊娠护理查房
- 2025年浙江省中考语文试题卷(含答案解析)
- 2025年副科级警察面试题及答案
- 2025 呼吸内科查房肺康复评估工具课件
- 2025年公安警察、辅警招聘知识考试题(附含答案)
- 2025年贵州建筑中级试题及答案
- 收银奖惩管理办法
- 浙江摆摊管理办法
评论
0/150
提交评论