0

Mirrored words

i am looking for help how can i write a programme whitch tell if (inserted word is mirrored or not) ex: assa is mirrored abc is not mirrored mom is mirrored

6th Aug 2017, 6:07 PM
Alexander
Alexander - avatar
11 ответов
+ 2
The code you wanted is a palindrome checker https://code.sololearn.com/cvjGwezuLIr8/?ref=app
6th Aug 2017, 8:14 PM
Manual
Manual - avatar
+ 2
I had made a code to mirror inputs in the past. https://code.sololearn.com/cm8HPNok72Td/?ref=app
6th Aug 2017, 8:09 PM
Manual
Manual - avatar
+ 1
It looks like what you want is code to check for a palindrome. You can google c++ palindrome and probably find code that will work for you. It's relatively simple code so I'll give you an idea of how it is usually done. In a loop (usually a for loop) get the first and last character of the word and compare them to each other. If they match move up one character from the beginning of the word and back one character from the the end of the word. Repeat until all characters have been checked as long as they continue to match otherwise exit the loop if they don't as it is not a palindrome. If all characters match it is a palindrome. If you need more help than that after trying, just ask.
6th Aug 2017, 6:26 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
The simplest and most generic way would be to just reverse the string and compare it to the original like this: inline bool isMirrored(std::string& str) { std::string temp = str; std::reverse(str.begin(), str.end()); return str == temp; } but @ChaoticDawg's answer would be the most efficient
6th Aug 2017, 6:32 PM
aklex
aklex - avatar
+ 1
#include <iostream> using namespace std; //Compiler version g++ 6.3.0 int main() { char word[10],word1[10]; cout<<"enter word of 10 letters"; cin>>word[10]; int i,j,temp=0; for(i;i<5;i++){ temp =word[10-1-i]; word[10-1-i]=word[i]; word[i]=temp; } if (word==word1) cout<<"y"; else cout<<"no"; }
6th Aug 2017, 6:37 PM
Ashutosh Srivastava
Ashutosh Srivastava - avatar
0
thank you guys. thanks chathotic dawg.
6th Aug 2017, 6:39 PM
Alexander
Alexander - avatar
0
(ashutosh) thanks but you did't give the user the option of the word length.😅
6th Aug 2017, 6:41 PM
Alexander
Alexander - avatar
0
you can do it using an if else statement
6th Aug 2017, 6:43 PM
Ashutosh Srivastava
Ashutosh Srivastava - avatar
0
my code is just a hint you have to tweak it
6th Aug 2017, 6:43 PM
Ashutosh Srivastava
Ashutosh Srivastava - avatar
0
then it'll be long programme to write.
6th Aug 2017, 6:45 PM
Alexander
Alexander - avatar
0
yup
6th Aug 2017, 6:46 PM
Ashutosh Srivastava
Ashutosh Srivastava - avatar