chore(CPlusPlus): add palindrome (#483)
Co-authored-by: Rahul Rajeev Pillai <66192267+Ashborn-SM@users.noreply.github.com>pull/449/head^2
parent
425005e751
commit
1e53be5fed
|
@ -0,0 +1,21 @@
|
|||
// Program to find whether a number and word is palindrome or not.
|
||||
|
||||
#include<iostream> //header file
|
||||
using namespace std;
|
||||
int main() //Main function
|
||||
{
|
||||
string num_str = ""; //define variable
|
||||
cin >> num_str; //taking input from user
|
||||
string new_str = ""; //define a new variable
|
||||
|
||||
for(int x = (num_str.size()-1); x >= 0; x--){ //for loop started
|
||||
new_str += num_str[x]; //assigning the value input by user to new variable in reverse order
|
||||
} //for loop end
|
||||
|
||||
cout << (num_str == new_str ? "palindrome" : "Non-palindrome"); //checking whether the value assigned to both variables is equal or not using ternary operator and printing whether it's palindrome or non-palindrome
|
||||
|
||||
return 0; //returning the main function
|
||||
}
|
||||
|
||||
//complexity of the program is O(n)
|
||||
//test cases:- 101,pop,asdfgfdsa,123454321,obobo,nancyiycnan etc.
|
|
@ -123,7 +123,8 @@
|
|||
3. [Prime Sieve](Maths/prime-sieve.cpp)
|
||||
4. [Fibonacci Series](Maths/fibonaccci-series.cpp)
|
||||
5. [Armstrong Number](Maths/armstrong.cpp)
|
||||
6. [Reverse digit of a number](Maths/reverse-digits.cpp)
|
||||
6. [Palindrome](Maths/palindrome.cpp)
|
||||
7. [Reverse digit of a number](Maths/reverse-digits.cpp)
|
||||
|
||||
# Recursion
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ A palindrome is a word, phrase, number or sequence of words that reads the same
|
|||
|
||||
## Implementation
|
||||
- [C](../../../algorithms/C/strings/palindrome.c)
|
||||
- [C++](../../../algorithms/CPlusPlus/Maths/palindrome.cpp)
|
||||
- [C#](../../../algorithms/CSharp/src/Strings/palindrome.cs)
|
||||
- [Haskell](../../../algorithms/Haskell/strings/palindrome.hs)
|
||||
- [Java](../../../algorithms/Java/strings/palindrome.java)
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
## 実装
|
||||
- [C](../../../algorithms/C/strings/palindrome.c)
|
||||
- [C++](../../../algorithms/CPlusPlus/Maths/palindrome.cpp)
|
||||
- [C#](../../../algorithms/CSharp/src/Strings/palindrome.cs)
|
||||
- [Haskell](../../../algorithms/Haskell/strings/palindrome.hs)
|
||||
- [Java](../../../algorithms/Java/strings/palindrome.java)
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
## 程式碼
|
||||
- [C](../../../algorithms/C/strings/palindrome.c)
|
||||
- [C++](../../../algorithms/CPlusPlus/Maths/palindrome.cpp)
|
||||
- [C#](../../../algorithms/CSharp/src/Strings/palindrome.cs)
|
||||
- [Haskell](../../../algorithms/Haskell/strings/palindrome.hs)
|
||||
- [Java](../../../algorithms/Java/strings/palindrome.java)
|
||||
|
|
Loading…
Reference in New Issue