zoukankan      html  css  js  c++  java
  • 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
    样例输出
    1/2

     1 import java.text.NumberFormat;
     2 import java.util.Arrays;
     3 import java.util.Scanner;
     4 
     5 public class Main {
     6     public static void main(String[] args) {
     7         Scanner scanner=new Scanner(System.in);
     8         char s[]=new char[65536];
     9         int number;
    10         int i;
    11         int count;
    12         double chu;
    13         int flag=0;
    14         
    15         number=scanner.nextInt();
    16         s=scanner.next().toCharArray();
    17         
    18         count=0;
    19         for(i=0;i<s.length;i++){
    20             if(s[i]=='U')
    21                 count++;
    22             
    23             else if(s[i]=='S')
    24                 flag=1;
    25         }
    26         
    27         chu=count*1.0/number;
    28         
    29         if(Math.abs(chu-0.5)<=0.003){
    30             System.out.println(count/gcd(count,number)+"/"+number/gcd(count,number));
    31             
    32         }
    33         else{
    34             if(flag==1)
    35                 System.out.println("Bingo");
    36             
    37             else
    38                 System.out.println("Fail");
    39         }    
    40     } 
    41     
    42     static int gcd(int a,int b){
    43         int temp;
    44         
    45         if(a<b){
    46             temp=a;
    47             a=b;
    48             b=temp;
    49         }
    50         
    51         while(a%b!=0){
    52             temp=a%b;
    53             a=b;
    54             b=temp;
    55         }
    56         return b;
    57     }
    58 }
     
  • 相关阅读:
    winfrom 获取当前系统时间
    netcore3.1API+efcore快速搭建
    php
    php
    php
    php-array的相关函数使用
    php-正则表达式
    vim的复制与粘贴
    vim的多窗口和文件切换操作
    laravel教程中出现500问题
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/4132239.html
Copyright © 2011-2022 走看看