-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrainbowa2.cpp
118 lines (100 loc) · 1.52 KB
/
rainbowa2.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <bits/stdc++.h>
using namespace std;
int main()
{
int test,n;
int arr[100];
cin >> test;
while(test--)
{
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> arr[i];
}
int flag=0;
int sum=0;
for (int i = 1; i <= 10; ++i)
{
flag=0;
for (int j = 1; j <= n; ++j)
{
if (i == arr[j] && flag == 0)
{ //cout<< i << " " << arr[j] << endl;
sum +=arr[j];
flag=1;
}
}
}
//cout << sum << endl;
unordered_map<int, int> umap,umap1;
if (sum > 28)
{
printf("no\n");
}
else
{
for (int i = 1; i <=n ; ++i)
{
if (arr[i] == 7)
{
break;
}
else
{
umap[arr[i]]++;
}
}
for (int i = n; i > 0 ; --i)
{
if (arr[i] == 7)
{
break;
}
else
{
umap1[arr[i]]++;
}
}
unordered_map<int ,int >:: iterator p ;
int a = umap.size();
int b = umap1.size();
int count=0;
//cout << a <<" " << b << endl;
if (a<=b)
{
for(int i = 1 ; i <= b;i++)
{
if (umap[i] == umap1[i] && umap[i]!=0)
{
count=count+1;
//cout << count << "yeh hai count pehle loop"<<endl;
}
}
if (count == a)
{
printf("yes\n");
}
else
printf("no\n");
}
else
{
for(int i = 1 ; i <= a;i++)
{
if (umap[i] == umap1[i] && umap1[i]!=0)
{
count=count+1;
//cout << count << "yeh hai count"<<endl;
}
}
if (count == b)
{
printf("yes\n");
}
else
printf("no\n");
}
}
}
}