Skip to content

Commit b2b3704

Browse files
committed
31/10/22
1 parent d1ae849 commit b2b3704

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed

.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"string": "cpp"
4+
}
5+
}

Palindrome_String.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
3+
https://practice.geeksforgeeks.org/problems/palindrome-string0817/1
4+
5+
6+
Input: S = "abba"
7+
Output: 1
8+
Explanation: S is a palindrome
9+
Example 2:
10+
11+
Input: S = "abc"
12+
Output: 0
13+
Explanation: S is not a palindrome
14+
15+
*/
16+
17+
int isPalindrome(string s)
18+
{
19+
// Your code goes here
20+
int n=s.length();
21+
int f=0;
22+
for(int i=0;i<n/2;i++)
23+
{
24+
if(s[i]!=s[n-i-1])
25+
{
26+
f=1;
27+
}
28+
}
29+
if(f==1)
30+
{
31+
return 0;
32+
}else
33+
return 1;
34+
}

Reverse_Word_in_String.cpp

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
3+
https://practice.geeksforgeeks.org/problems/reverse-words-in-a-given-string5459/1
4+
5+
Input:
6+
S = i.like.this.program.very.much
7+
Output: much.very.program.this.like.i
8+
Explanation: After reversing the whole
9+
string(not individual words), the input
10+
string becomes
11+
much.very.program.this.like.
12+
13+
14+
Input:
15+
S = pqr.mno
16+
Output: mno.pqr
17+
Explanation: After reversing the whole
18+
string , the input string becomes
19+
mno.pqr
20+
21+
*/
22+
23+
string reverseWords(string s)
24+
{
25+
// code here
26+
reverse(s.begin(),s.end());
27+
int i=0;
28+
string st;
29+
vector<string>ans;
30+
31+
string ans1="";
32+
int j=s.length();
33+
string t;
34+
while(s[j]!='.') // only push when "." occur so 1st word Not pushed .
35+
{
36+
t=t+s[j];
37+
j--;
38+
}
39+
while(i!=s.length()+1)
40+
{
41+
if(s[i]=='.')
42+
{
43+
reverse(st.begin(),st.end()); //reverse of reverse
44+
ans.push_back(st);
45+
ans.push_back('.');
46+
st="";
47+
}
48+
else
49+
{
50+
st=st+s[i];
51+
}
52+
i++;
53+
}
54+
for(auto i:ans)
55+
{
56+
ans1=ans1+i;
57+
}
58+
return ans1+t;
59+
}

paranthesis_Checker.cpp

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
https://practice.geeksforgeeks.org/problems/parenthesis-checker2744/1
3+
4+
Given an expression string x. Examine whether the pairs and the orders of “{“,”}”,”(“,”)”,”[“,”]” are correct in exp.
5+
For example, the function should return 'true' for exp = “[()]{}{[()()]()}” and 'false' for exp = “[(])”.
6+
7+
Input:
8+
{([])}
9+
Output:
10+
true
11+
Explanation:
12+
{ ( [ ] ) }. Same colored brackets can form
13+
balaced pairs, with 0 number of
14+
unbalanced bracket.
15+
16+
Input:
17+
([]
18+
Output:
19+
false
20+
Explanation:
21+
([]. Here square bracket is balanced but
22+
the small bracket is not balanced and
23+
Hence , the output will be unbalanced.
24+
25+
26+
bool ispar(string x)
27+
{
28+
// Your code here
29+
stack<char> s;
30+
for(int i=0;i<x.length();i++)
31+
{
32+
if(s.empty())
33+
{
34+
s.push(x[i]);
35+
}
36+
else if((s.top()=='('&& x[i]==')') || (s.top()=='{' && x[i]=='}') || (s.top()=='[' && x[i]==']'))
37+
{
38+
s.pop();
39+
}
40+
else
41+
{
42+
s.push(x[i]);
43+
}
44+
}
45+
if(s.empty())
46+
{
47+
return true;
48+
}
49+
return false;
50+
}

0 commit comments

Comments
 (0)