-
Notifications
You must be signed in to change notification settings - Fork 19
/
Mirror_of_Mahatma_Gandhi.cpp
63 lines (60 loc) · 1.82 KB
/
Mirror_of_Mahatma_Gandhi.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
/*
On the way to Dandi March, Gandhijee carried a mirror with himself.
When he reached Dandi, he decided to play a game with the tired people to give them some strength.
At each turn of the game he pointed out a person and told him to say a number N(possibly huge) of his choice.
The number was called lucky if that equals it's mirror image.
Input:
First line contains number of test cases T. Each test case contains a single integer N.
Output:
For each test case print "YES" if the number was lucky else print "NO" (quotes for clarity) in one line.
Constraints:
1 ≤ T ≤ 100
0 ≤ N ≤ 10100
Image for Sample Test Cases :
Refer Question:
https://www.hackerearth.com/practice/algorithms/string-algorithm/basics-of-string-manipulation/practice-problems/algorithm/mirror-of-mahatma-gandhi/
*/
#include <bits/stdc++.h>
using namespace std;
void dandi(string s)
{
//first check if it is palindrome, a set of numbers will be mirror number if only its a palindrome ;)
//if its not palindrome, just print no
if(s != string(s.rbegin(), s.rend()))
{
cout<<"NO"<<endl;
}
else
{
//if its palindrome check if it contains either of non mirror numbers, even if any of these are present then its
// non mirror number
if(
(s.find('2') != string::npos) ||
(s.find('3') != string::npos) ||
(s.find('4') != string::npos) ||
(s.find('5') != string::npos) ||
(s.find('6') != string::npos) ||
(s.find('7') != string::npos) ||
(s.find('9') != string::npos)
)
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
}
}
}
int main()
{
int tc;
string n;
cin>>tc;
while(tc--)
{
cin>>n;
dandi(n);
}
return 0;
}