Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace loto_probability
- {
- class Program
- {
- static void Main(string[] args)
- {
- int totalLottoBalls = Convert.ToInt32(Console.ReadLine());
- int ballsExtracted = Convert.ToInt32(Console.ReadLine());
- string category = Console.ReadLine();
- switch (category)
- {
- case "II":
- long denominator = Combinations(ballsExtracted,(ballsExtracted-1)) * Combinations(totalLottoBalls-ballsExtracted, (ballsExtracted-(ballsExtracted - 1)));
- long nominator= Combinations(totalLottoBalls, ballsExtracted);
- Console.Write(Probability(denominator, nominator));
- break;
- case "III":
- long denominator2 = Combinations(ballsExtracted, ballsExtracted - 2) * Combinations(totalLottoBalls - ballsExtracted, (ballsExtracted - (ballsExtracted - 2)));
- long nominator2 = Combinations(totalLottoBalls, ballsExtracted);
- Console.Write(Probability(denominator2, nominator2));
- break;
- default:
- Console.Write(Probability(1, Combinations(totalLottoBalls, ballsExtracted)));
- break;
- }
- }
- static int Factorial(long number)
- {
- int factorial = 1;
- for(int i = 1; i <= number; i++)
- {
- factorial *= i;
- }
- return factorial;
- }
- static long Combinations(int n, int k)
- {
- long combinationsResult = Factorial(n) / (Factorial(k) * Factorial(n - k));
- return combinationsResult;
- }
- static double Probability(long goodCases,long totalCases)
- {
- double result=goodCases / totalCases;
- return Math.Round(result, 10);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement