南阳 OJ 204 (Coin Test)(字符串处理)
来源:互联网 发布:传智播客大数据下载 编辑:程序博客网 时间:2024/04/29 06:31
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"
- 样例输入
6UUUDDD
- 样例输出
1/2
- 来源
郑州大学校赛题目
代码:
题意:抛掷硬币,结果会出现正面,反面,或者站立在桌面上。给定一串字符,判断最后的可能性。
难点:题目中要求要用最简形式表示,如何化成最简形式?
思路:
化简分式可以用辗转相除法,求出最大公约数,然后分式上下同时除以最大公约数即可解决。
代码如下:
#include<stdio.h>#include<math.h>int main (){int i ,N ,a=0 ,b=0 ,m ,n ,temp ,r ;char s;scanf ("%d",&N);getchar();for (i=0 ; i<N ; i++){s=getchar();if(s =='S'){printf("Bingo");}if(s == 'U')++a;else++b;}m=a;n=b+a;if(n<m){temp = n;n = m;m = temp;}while(m!=0){r= n%m;n= m;m= r;}//辗转相除法 化成 最简的分式if(fabs((float)a/(a+b)-0.5)>0.003)printf("Fail");elseprintf("%d/%d",a/n,(a+b)/n);
return 0;}
- 南阳 OJ 204 (Coin Test)(字符串处理)
- 南阳OJ 204 Coin Test
- 南阳oj 题目204 Coin Test
- 南阳204 Coin Test
- 南阳 oj 语言入门 Coin test 题目204
- 南阳题目204-Coin Test
- Coin Test(南阳oj204)(水题)
- 南阳oj 字符串替换
- 南阳oj 915 +-字符串
- 南阳oj 回文字符串
- 南阳 OJ 217 a letter and a number (字符串处理)
- NYoj 204Coin Test(化简最简小数)
- nyoj-204Coin Test
- nyoj 204-Coin Test
- NYOJ 204 Coin Test
- nyoj-204Coin Test
- 204 Coin Test
- nyoj 204 Coin Test
- linux文件系统,dup2等
- 汇编入门学习笔记 (十三)—— 外中断
- 考研复试机试题(2009)
- [ext/iconv/iconv.lo] Error 1
- MySQL性能优化的最佳20+条经验
- 南阳 OJ 204 (Coin Test)(字符串处理)
- SEAndroid安全机制中的进程安全上下文关联分析
- hadoop错误解决方案参考 慢慢更新...
- 图像代数运算:平均值去噪,减去背景
- 黑马程序员--OC之Foundation框架
- 在PPTP VPN服务器上配置FreeRADIUS+daloRADIUS实现用户跟踪管理
- 强大的vim配置文件,让编程更随意
- JavaSe基础02——Hello World
- HDOJ 4849 Task (贪心)