Skip to content

Commit b738747

Browse files
authored
Merge pull request #542 from ri-tae-ka/fair-playoff
Add Fair Playoff Codeforces Solution
2 parents 383ce6d + 3d9b6d2 commit b738747

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

Arrays/Fair Playoff.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* Problem Statement:
2+
Four players participate in the playoff tournament. The tournament is held according to the following scheme: the first player will play with the second, and the third player with the fourth, then the winners of the pairs will play in the finals of the tournament.
3+
4+
It is known that in a match between two players, the one whose skill is greater will win. The skill of the i-th player is equal to si and all skill levels are pairwise different (i. e. there are no two identical values in the array s).
5+
6+
The tournament is called fair if the two players with the highest skills meet in the finals.
7+
8+
Determine whether the given tournament is fair.
9+
10+
Example:
11+
12+
Input:
13+
4
14+
3 7 9 5
15+
4 5 6 9
16+
5 3 8 1
17+
6 5 3 2
18+
19+
Output:
20+
YES
21+
NO
22+
YES
23+
NO
24+
*/
25+
26+
#include<iostream>
27+
using namespace std;
28+
29+
int main()
30+
{
31+
long int T;
32+
cin>>T;
33+
34+
while(T--)
35+
{
36+
int s[4], i, f1 = 0, f2 = 0, sm = 0, no = 0, yes = 0;
37+
for(i = 0; i < 4; i++)
38+
cin>>s[i]; //a 1-D array to store the skills of 4 players
39+
40+
if(s[0] > s[1]) //comparing first player with second
41+
f1 = s[0];
42+
43+
else
44+
f1 = s[1];
45+
46+
if(s[2] > s[3]) //comparing third player with fourth
47+
f2 = s[2];
48+
49+
else
50+
f2 = s[3];
51+
52+
53+
if(f2 - f1 > 0)
54+
sm = f1;
55+
else
56+
sm = f2;
57+
58+
59+
for(i = 0; i < 4; i++)
60+
{
61+
if(s[i] > sm) //to check if the finals were fair or not
62+
yes++; //assign 'yes' if the players with highest skills are in finals
63+
else
64+
no++; //assign 'no' if the players with highest skills were not in finals
65+
}
66+
if(yes == 1)
67+
cout<<"YES"<<endl; //print 'YES' for a fair playoff
68+
else
69+
cout<<"NO"<<endl; //print 'NO' for an unfair playoff
70+
}
71+
return 0;
72+
}

0 commit comments

Comments
 (0)