Skip to content

Commit

Permalink
Day2 (#27)
Browse files Browse the repository at this point in the history
* Add @imkaka as a contributor

* Day2 Cpp
  • Loading branch information
imkaka authored and MadhavBahl committed Dec 22, 2018
1 parent 2dbc909 commit 40c87f7
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 7 deletions.
Binary file added Day2/C++/checkPalindrome
Binary file not shown.
33 changes: 33 additions & 0 deletions Day2/C++/checkPalindrome.cpp
@@ -0,0 +1,33 @@
/*
* @author: imkaka
* @date : 21/12/2018
*/

#include<iostream>
#include<string>

using namespace std;

int main(){

string str;
cin >> str ;

int size = str.size();
bool flag = false;
for(int i = 0; i< size/2; i++)
{
if(str[i] != str[size-i-1])
{
flag = true;
break;
}
}

if(!flag)
cout << str <<" is a Palindrome!!" << endl;
else
cout << str << " is NOT a Palindrome!" << endl;

return 0;
}
Binary file added Day2/C++/reversString
Binary file not shown.
27 changes: 27 additions & 0 deletions Day2/C++/reversString.cpp
@@ -0,0 +1,27 @@
/*
* @author: imkaka
* @date : 21/12/2018
*/

#include<iostream>
#include<string>

using namespace std;

int main(){

string str;
cin >> str ;

int size = str.size();
for(int i = 0; i< size/2; i++)
{
char temp = str[i];
str[i] = str[size-i-1];
str[size-1-i] = temp;
}

cout << str << endl;

return 0;
}
80 changes: 73 additions & 7 deletions Day2/README.md
Expand Up @@ -65,10 +65,10 @@ function strRev (str) {
var i, j,
len = str.length,
tempArr = [];

// Read string in reverse order and store each letter in the array
for (j=len-1; j>=0; j--) {
tempArr.push(str[j]);
tempArr.push(str[j]);
}

// Join the tempArr to convert it into a string
Expand All @@ -93,7 +93,7 @@ function strRev (str) {
var i, j,
len = str.length,
tempArr = [];

// Read string in reverse order and store each letter in the array
for (i=0, j=len-1; i<len; i++, j--) {
tempArr[i] = str[j]; // You can use push() instead of assigning by index
Expand Down Expand Up @@ -217,7 +217,35 @@ public class Reverse {
}
}

```
## C++ Implementation

### [Cpp Solution](./C++/reverseString.cpp)

```cpp
/*
* @author: imkaka
* @date : 21/12/2018
*/

#include<iostream>
#include<string>

using namespace std;

int main(){

string str;
cin >> str ;

int size = str.size();
for(int i = 0; i< size/2; i++)
{
char temp = str[i];
str[i] = str[size-i-1];
str[size-1-i] = temp;
}

cout << str << endl;

## Python Implementation

Expand Down Expand Up @@ -400,7 +428,7 @@ isPalindrome('level');
* @author MadhavBahlMD
* @date 21/12/2018
*/

import java.util.Scanner;

public class Palindrome {
Expand Down Expand Up @@ -439,7 +467,7 @@ public class Palindrome {
* @author MadhavBahlMD
* @date 21/12/2018
*/

import java.util.Scanner;
// Method 2: Check whether reversed string is equal to the original string

Expand All @@ -458,7 +486,7 @@ public class Palindrome2 {
for (int i=0; i<str.length(); i++) {
reversed = str.charAt(i) + reversed;
}

// Check if the reversed string is same as the original string
if (str.equals(reversed)) {
System.out.println ("The given string \"" + str + "\" is a Palindrome");
Expand All @@ -469,6 +497,44 @@ public class Palindrome2 {
}
```

### [C++ Implementation](./C++/checkPalindrome.cpp)

```cpp
/*
* @author: imkaka
* @date : 21/12/2018
*/

#include<iostream>
#include<string>

using namespace std;

int main(){

string str;
cin >> str ;

int size = str.size();
bool flag = false;
for(int i = 0; i< size/2; i++)
{
if(str[i] != str[size-i-1])
{
flag = true;
break;
}
}

if(!flag)
cout << str <<" is a Palindrome!!" << endl;
else
cout << str << " is NOT a Palindrome!" << endl;

return 0;
}


## Python Implementation

### [Solution 1](./Python/Palindrome.py)
Expand Down

0 comments on commit 40c87f7

Please sign in to comment.