这里是10.29随笔。
这里留一下今天写的代码,用队列实现回文:
include
include
include
bool isPalindrome(const std::string& str) {
int left = 0;
int right = str.size() - 1;
while (left < right) {
while (left < right && isspace(str[left])) {
++left;
}
while (left < right && isspace(str[right])) {
--right;
}
if (str[left] != str[right]) {
return false;
}
++left;
--right;
}
return true;
}
int main() {
std::string s;
std::getline(std::cin, s); // read a line of input
if (isPalindrome(s)) {
std::cout << "该字符串是回文字符串" << std::endl;
} else {
std::cout << "该字符串不是回文字符串" << std::endl;
}
return 0;
}
标签:std,right,int,10.29,str,随笔,left From: https://www.cnblogs.com/Thanatos-syst/p/18514165