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
11 odpowiedzi
+ 2
The code you wanted is a palindrome checker
https://code.sololearn.com/cvjGwezuLIr8/?ref=app
+ 2
I had made a code to mirror inputs in the past.
https://code.sololearn.com/cm8HPNok72Td/?ref=app
+ 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.
+ 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
+ 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";
}
0
thank you guys.
thanks chathotic dawg.
0
(ashutosh) thanks but you did't give the user the option of the word length.😅
0
you can do it using an if else statement
0
my code is just a hint you have to tweak it
0
then it'll be long programme to write.
0
yup