-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCONTEST_26_Basic_Probability_Puzzles_#10.cpp
67 lines (52 loc) · 1.28 KB
/
CONTEST_26_Basic_Probability_Puzzles_#10.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//Ques Link - https://www.hackerrank.com/contests/int213-contest26/challenges/basic-probability-puzzles-10/submissions/code/1350129838
#include <stdbool.h>
#include <stdio.h>
#include <iostream>
using namespace std;
void ConvertToLowestTerms(int &firstNum, int &secondNum)
{
int Low_Value, High_Value;
if(firstNum > secondNum)
{
Low_Value = secondNum;
High_Value = firstNum;
}
else
{
High_Value = secondNum;
Low_Value = firstNum;
}
for(int i = Low_Value; i > 0;i--)
{
if((Low_Value % i == 0) && (High_Value % i == 0))
{
firstNum = firstNum/i;
secondNum = secondNum/i;
break;
}
}
}
struct candidate
{
int selected_top;
int not_selected_top;
int bottom;
void init (int top, int bottom)
{
this->selected_top = top;
this->bottom = bottom;
this->not_selected_top = bottom - top;
}
};
int main ()
{
candidate Bill, Nina;
Bill.init(1,3);
Nina.init(1,5);
int top = (Bill.selected_top * Nina.not_selected_top) +
(Bill.not_selected_top * Nina.selected_top);
int bottom = Bill.bottom * Nina.bottom;
ConvertToLowestTerms(top, bottom);
printf("%d/%d", top, bottom);
return 0;
}