Skip to content

Commit 7539b56

Browse files
committed
Save Ironman
1 parent 4a117c7 commit 7539b56

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

Some_More_Strings/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,13 @@
7272
Input: geeksforgeeks, forgeeksgeeks
7373
Output: 1
7474
Explanation: s1 is geeksforgeeks, s2 is forgeeksgeeks. Clearly, s2 is a rotated version of s1 as s2 can be obtained by left-rotating s1 by 5 units.
75+
76+
## 9. Save Ironman:
77+
Jarvis is weak in computing palindromes for Alphanumeric characters.
78+
While Ironman is busy fighting Thanos, he needs to activate sonic punch but Jarvis is stuck in computing palindromes.
79+
You are given a string S containing alphanumeric characters. Find out whether the string is a palindrome or not.
80+
If you are unable to solve it then it may result in the death of Iron Man.
81+
Example 1:
82+
Input : S = "I am :IronnorI Ma, i"
83+
Output : YES
84+
Explanation: Ignore all the symbol and whitespaces S = "IamIronnorIMai". Now, Check for pallandrome ignoring uppercase and lowercase english letter.

Some_More_Strings/SaveIronMan.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// { Driver Code Starts
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
5+
bool saveIronman(string ch);
6+
7+
8+
int main()
9+
{
10+
int t,b,c,d,e,f,g,h;
11+
cin>>t;
12+
char cc;
13+
cc = getchar();
14+
15+
while(t--)
16+
{
17+
string ch;
18+
getline(cin,ch);
19+
20+
if(saveIronman(ch)){
21+
cout << "YES\n";
22+
}
23+
else{
24+
cout << "NO\n";
25+
}
26+
27+
}
28+
}
29+
// } Driver Code Ends
30+
31+
32+
33+
bool saveIronman(string ch)
34+
{
35+
// Complete the function
36+
string s;
37+
for(int i = 0 ; i < ch.length() ; i++)
38+
{
39+
if((tolower(ch[i]) >= 'a' && tolower(ch[i]) <= 'z') || (ch[i] >= '0' && ch[i] <= '9'))
40+
s += tolower(ch[i]);
41+
}
42+
int i = 0, j = s.length() - 1;
43+
while(i < j)
44+
{
45+
if(s[i++] != s[j--])
46+
return false;
47+
}
48+
return true;
49+
}

0 commit comments

Comments
 (0)