-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathManasa_loves_Maths.cpp
More file actions
60 lines (54 loc) · 1.18 KB
/
Manasa_loves_Maths.cpp
File metadata and controls
60 lines (54 loc) · 1.18 KB
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
// https://www.hackerrank.com/challenges/manasa-loves-maths/problem
#include <bits/stdc++.h>
using namespace std;
bool ok(int i, int j, int k, string s)
{
if(((s[i] - '0')*100 + (s[j] - '0')*10 + (s[k] - '0')) % 8 == 0)
return true;
return false;
}
string solve(string s)
{
int len = s.length();
if(len == 1)
{
if((s[0]-'0') % 8 == 0)
return "YES";
else
return "NO";
}
else if(len == 2)
{
if(((s[1]-'0')*10+(s[0]-'0')) % 8 == 0 || ((s[0]-'0')*10 + (s[1]- '0')) % 8 == 0)
return "YES";
else
return "NO";
}
else
{
for(int i = 0; i < len-2; i++)
{
for(int j = i+1; j < len-1; j++)
{
for(int k = j+1; k < len; k++)
{
if(ok(i, j, k, s) || ok(i, k, j, s) || ok(j, i, k, s) || ok(j, k, i, s) || ok(k, i, j, s) || ok(k, j, i, s))
return "YES";
}
}
}
return "NO";
}
}
int main()
{
int t;
cin >> t;
while(t--)
{
string s;
cin >> s;
cout << solve(s) << endl;
}
return 0;
}