38-语言入门-38-Coin Test
As is known to all,if you throw a coin up and let it droped on the desk there are usually three results. Yes,just believe what I say ~it can be the right side or the other side or standing on the desk, If you don't believe this,just try In the past there were some famous mathematicians working on this .They repeat the throwing job once again. But jacmy is a lazy boy.He is busy with dating or playing games.He have no time to throw a single coin for 100000 times. Here comes his idea,He just go bank and exchange thousands of dollars into coins and then throw then on the desk only once. The only job left for him is to count the number of coins with three conditions.
He will show you the coins on the desk to you one by one. Please tell him the possiblility of the coin on the right side as a fractional number if the possiblity between the result and 0.5 is no larger than 0.003. BE CAREFUL that even 1/2,50/100,33/66 are equal only 1/2 is accepted ! if the difference between the result and 0.5 is larger than 0.003,Please tell him "Fail".Or if you see one coin standing on the desk,just say "Bingo" any way.
输入
Three will be two line as input.
The first line is a number N(1<N<65536)
telling you the number of coins on the desk.
The second line is the result with N litters.The letter are "U","D",or "S","U" means the coin is on the right side. "D" means the coin is on the other side ."S" means standing on the desk.
输出
If test successeded,just output the possibility of the coin on the right side.If the test failed please output "Fail",If there is one or more"S",please output "Bingo"
样例输入
6
UUUDDD
样例输出
#include <math.h>
//处理数据
static void handlerData(int readCount);
//计算a和b的最大公约数
static int calCommonDivisor(int a,int b);
int main()
{
int readCount = 0;
scanf("%d",&readCount);
getchar();
handlerData(readCount);
return 0;
}
//处理数据
static void handlerData(int readCount)
{
//输入总数
int inputCount = readCount;
//right side
int rightSide = 0;
//other side
int otherSide = 0;
int isBingo = 0;
while (readCount > 0)
{
char inputChar;
scanf("%c",&inputChar);
if (inputChar == 'U')
{
++rightSide;
}
else if(inputChar == 'D')
{
++otherSide;
}
else
{
isBingo = 1;
}
--readCount;
}
if (isBingo == 1)
{
printf("Bingo\n");
return;
}
// 0.003 0.5
if(6*inputCount > 2000 * rightSide ||
1000 * inputCount < 2000 * rightSide)
{
printf("Fail\n");
return;
}
//分母通分
int tmpValue = calCommonDivisor(rightSide,inputCount);
printf("%d/%d\n",rightSide/tmpValue,inputCount/tmpValue);
}
//计算a和b的最大公约数
static int calCommonDivisor(int a,int b)
{
int maxNum = a>b?a:b;
int minNum = a<b?a:b;
int midResult = maxNum % minNum;
while(midResult != 0)
{
maxNum = minNum;
minNum = midResult;
midResult = maxNum % minNum;
}
return minNum;
38-语言入门-38-Coin Test的更多相关文章
- Delphi XE2 之 FireMonkey 入门(38) - 控件基础: TPopupMenu、TMenuItem、TMenuBar、TMainMenu
Delphi XE2 之 FireMonkey 入门(38) - 控件基础: TPopupMenu.TMenuItem.TMenuBar.TMainMenu 相关控件: TMenuBar.TPopup ...
- 【南阳OJ分类之语言入门】80题题目+AC代码汇总
小技巧:本文之前由csdn自动生成了一个目录,不必下拉一个一个去找,可通过目录标题直接定位. 本文转载自本人的csdn博客,复制过来的,排版就不弄了,欢迎转载. 声明: 题目部分皆为南阳OJ题目. 代 ...
- C语言入门(21)——使用DBG对C语言进行调试
C语言入门(21)--使用DBG对C语言进行调试 程序中除了一目了然的Bug之外都需要一定的调试手段来分析到底错在哪.到目前为止我们的调试手段只有一种:根据程序执行时的出错现象假设错误原因,然后在代码 ...
- 《JavaScript语言入门教程》记录整理:面向对象
目录 面向对象编程 实例对象与 new 命令 this关键字 对象的继承 Object对象的方法 严格模式(strict mode) 本系列基于阮一峰老师的<JavaScrip语言入门教程> ...
- C语言入门教程-(3)基本数据类型
1.数据类型 在C语言中,数据类型指的是用于声明不同类型的变量或函数的一个广泛的系统.C语言数据类型可以分为四种: 1.基本类型:它们是算术类型,包括两种类型:整数类型和浮点类型. 2.枚举类型:它们 ...
- 踢爆IT劣书出版黑幕——由清华大学出版社之《C语言入门很简单》想到的(1)
1.前言与作者 首先声明,我是由于非常偶然的机会获得<C语言入门很简单>这本书的,绝对不是买的.买这种书实在丢不起那人. 去年这书刚出版时,在CU论坛举行试读推广,我当时随口说了几句(没说 ...
- 我为什么反对推荐新人编程C/C++语言入门?
虽然我接触编程以及计算机时间比较早,但是正式打算转入程序员这个行当差不多是大学第四年的事情 从03年接触计算机,07年开始接触计算机编程, 期间接触过的技术包括 缓冲区溢出(看高手写的shellcod ...
- 《C语言入门1.2.3—一个老鸟的C语言学习心得》—清华大学出版社炮制的又一本劣书及伪书
<C语言入门1.2.3—一个老鸟的C语言学习心得>—清华大学出版社炮制的又一本劣书及伪书 [薛非评] 区区15页,有80多个错误. 最严重的有: 通篇完全是C++代码,根本不是C语言代码. ...
- c语言入门教程 / c语言入门经典书籍
用C语言开始编写代码初级:C语言入门必备(以下两本书任选一本即可) C语言是作为从事实际编程工作的程序员的一种工具而出现的,本阶段的学习最主要的目的就是尽快掌握如何用c语言编写程序的技能.对c语言的数 ...
- 【转】c语言入门教程 / c语言入门经典书籍
用C语言开始编写代码 初级:C语言入门必备 (以下两本书任选一本即可) C语言是作为从事实际编程工作的程序员的一种工具而出现的,本阶段的学习最主要的目的就是尽快掌握如何用c语言编写程序的技能.对c语言 ...
随机推荐
- HDU 5568 sequence2 区间dp+大数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5568 题意: 求所有长度为k的严格升序子序列的个数. 题解: 令dp[i][k]表示以i结尾的长度为 ...
- hdu 2255 奔小康赚大钱 最大权匹配KM
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2255 传说在遥远的地方有一个非常富裕的村落,有一天,村长决定进行制度改革:重新分配房子.这可是一件大事 ...
- [转载]为什么我希望用C而不是C++来实现ZeroMQ
来源: http://blog.jobbole.com/19647/ 开始前我要先做个澄清:这篇文章同Linus Torvalds这种死忠C程序员吐槽C++的观点是不同的.在我的整个职业生涯里我都在使 ...
- C# 中的 == 和 equals()有什么区别?
如以下代码: 1 2 3 4 5 6 7 8 9 int age = 25; short newAge = 25; Console.WriteLine(age == newAge); //t ...
- httpClient多线程请求
使用httpClient可模拟请求Url获取资源,使用单线程的请求速度上会有一定的限制,参考了Apache给出的例子,自己做了测试实现多线程并发请求,以下代码需要HttpClient 4.2的包,可以 ...
- Selenium获取input输入框中值的三种方法
第一种用jQuery的val方法: js = "return $('input').val();" driver.execute_script(js) 第二种用jQuery的att ...
- POJ3469 Dual Core CPU(最小割)
题意:给你n个模块,每个模块在A核花费为ai,在B核跑花费为bi,然后由m个任务(ai,bi,wi),表示如果ai,bi不在同一个核上跑,额外的花费为wi,求最小的花费. 一开始想的时候以为是费用流, ...
- ***Jquery下Ajax与PHP数据交换
一.前台传递字符串变量,后台返回字符串变量(非json格式) Javascript代码: 这里,为了解决Ajax数据传递出现的汉字乱码,在字符串传递之前,使用javascript函数escape()对 ...
- C# JSON字符串序列化与反序列化
JSON与c#对象转换http://hi.baidu.com/donick/item/4d741338870c91fe97f88d33 C# JSON字符串序列化与反序列化 – http://www. ...
- POJ 3384 Feng Shui(半平面交向内推进求最远点对)
题目链接 题意 : 两个圆能够覆盖的最大多边形面积的时候两个圆圆心的坐标是多少,两个圆必须在多边形内. 思路 : 向内推进r,然后求多边形最远的两个点就是能覆盖的最大面积. #include < ...