Я пытаюсь заставить эту функцию работать, она должна взять входную строку, а затем изменить ее на все строчные буквы, а затем избавиться от всех пробелов и знаков препинания, но я не могу ее получить работа ... У меня есть часть к концу, которая прокомментирована, и я не думаю, что она мне нужна, но я не могу сказать ... если кто-нибудь может понять, что эта помощь будет оценена!C++ Получение максимального палиндрома
bool PalindromeFinder::isPalindrome(string input) {
//TODO define isPalindrome with the desired functionality
// make new string without the spaces and special characters
//isSpace and isPunct if space or thing then omit to make it a clean string
//need to store largest palindrome so far that was found
// make a string cleanString
string cleanString = "";
//make the string all lowercase
transform(input.begin(), input.end(), input.begin(), ::tolower);
for (int i=0; i <= input.length(); i++) {
char cha = input[cha];
// now, if there is punctuation or a space, then remove it
if (ispunct(cha) || isspace(cha)) {
//remove the punctuation or space
input.erase(cha) == cleanString;
}
}
// for (int i=1; i <= input.length(); i++){
// // check to make sure there are no spaces or punctuation
// if (!ispunct(cha) && !isspace(cha))
// {
// //if there isnt then build the word...ex) e > ex > exa > exam
// input += cha;
//
// //this line is for testing
// cout << "This is my clean string: " << input << endl;
//
// }
//
//
// }
//make a empty string to use as a template
string revString = "";
// for all of the chars in the string, reverse them
for (int i = cleanString.length()-1; i >= 0; i--)
{
// use this to access array index
// add the letters back
revString += cleanString[i];
}
// now check and make sure that it equals each other...
if (cleanString == revString)
{
// if it does, return true
return true;
}
//otherwise return false
else return false;
}
Пожалуйста, опишите проблему. «получить самый большой палиндром» недостаточно. –
"input.erase (cha) == cleanString" вы уверены, что хотите делать двойные равны здесь. –
char cha = input [cha] ??? input.erase (cha) == cleanString; ??? Я думаю, это не настоящая копия/вставка вашего кода. –