forked from AllAlgorithms/cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindrome_check.cpp
More file actions
40 lines (38 loc) · 796 Bytes
/
Copy pathpalindrome_check.cpp
File metadata and controls
40 lines (38 loc) · 796 Bytes
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
//
// C/C++ program to check whether the given string is a palindrome
//
// The All ▲lgorithms Project
//
// https://allalgorithms.com/strings
// https://github.com/allalgorithms/cpp
//
// Contributed by: Sankalp Godghate
// Github: @sankalp24
//
#include<bits/stdc++.h>
using namespace std;
// A function to check if a string str is palindrome
void isPalindrome(string str)
{
// Start from leftmost and rightmost corners of str
int l = 0;
int h = str.size() - 1;
// Keep comparing characters while they are same
while (h > l)
{
if (str[l++] != str[h--])
{
cout<<str<<" is not a Palindrome";
return;
}
}
cout<<str<<" is a palindrome";
}
// Driver program to test above function
int main()
{
string str;
cin>>str;
isPalindrome(str);
return 0;
}