閱讀663 返回首頁    go 阿裏雲 go 技術社區[雲棲]


Coin Test

Coin Test

時間限製:3000 ms  |  內存限製:65535 KB
難度:1
描述

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
樣例輸出
1/2

查看代碼---運行號:252134----結果:Accepted

運行時間:2012-10-05 09:29:04  |  運行人:huangyibiao
01.#include <iostream>
02.#include <cmath>
03. 
04.using namespace std;
05.#define MAX_LEN 65536
06.int main()
07.{
08.int nCoins;//硬幣
09.char str[MAX_LEN];
10. 
11.cin >> nCoins;
12.cin >> str;
13. 
14.int u = 0, d = 0, s = 0;
15.for (int i = 0; str[i] != '\0'; i++)
16.{
17.if (str[i] == 'U')
18.u++;
19.else if (str[i] == 'D')
20.d++;
21.else if (str[i] == 'S')
22.s++;
23.}
24.if (s != 0)
25.{
26.cout << "Bingo\n";
27.}
28.else if (fabs(1.0*u / (double)nCoins - 1.0/2.0) > 0.003)
29.{
30.cout << "Fail\n";
31.}
32.else
33.{
34.int r, m = u, n = nCoins;//保存原來的變量值
35.while (n)
36.{
37.r = m % n;
38.m= n;
39.n = r;
40.}
41.cout << u / m<< "/" << nCoins / m << endl;
42.}
43.return 0;
44.}

最後更新:2017-04-03 05:40:25

  上一篇:go jdk1.5和jdk1.6對於@override支持的區別
  下一篇:go oracle中兩表之間值互相插入和表自身插入值