-
Notifications
You must be signed in to change notification settings - Fork 7
/
balanced-contest-or-not.cpp
83 lines (81 loc) · 1.07 KB
/
balanced-contest-or-not.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//https://www.hackerrank.com/contests/101hack27/challenges/balanced-contest-or-not
//mandeep singh @msdeep14
#include<iostream>
using namespace std;
void insertion(int a[], int s)
{
int i, j;
int current;
for(i = 1; i< s; i++)
{
current = a[i];
for(j = i-1; j>=0; j--)
{
if(current < a[j])
a[j+1] = a[j];
else
break;
}
a[j+1] = current;
}
}
int main()
{
int i,j,n,k,l,val1[5],val2[5],flag;
int b[5],d[5],b1[5],d1[5];
for(i=0;i<5;i++)
{
cin>>b[i];
cin>>d[i];
}
for(i=0;i<5;i++)
{
b1[i]=b[i];
d1[i]=d[i];
}
insertion(b1,5);
insertion(d1,5);
//check values
k=0;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(b1[i]==b[j])
{
val1[k]=j;
k++;
break;
}
}
}
k=0;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(d1[i]==d[j])
{
val2[k]=j;
k++;
break;
}
}
}
for(i=0;i<5;i++)
{
flag=0;
if(val1[i]==val2[i])
{
//do nothing;
flag=1;
}
else
break;
}
if(flag==1)
cout<<"1";
else
cout<<"0";
return 0;
}