10.29随笔

这里是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;

}

posted @ 2024-10-29 18:56  Thanatos。syts  阅读(28)  评论(0)    收藏  举报