Untitled
#include <iostream> #include <cctype> #include <cstring> using namespace std; bool isPalindrome(const char *word, int length) { if(length == 1) return true; int start = 0, end = length - 1; while (start < end) { if (tolower(word[start]) != tolower(word[end])) return false; start++; end--; } return true; } int main() { int n; cin >> n; cin.ignore(); for (int i = 0; i < n; i++) { char sent[100]; cin.getline(sent, 100); int counter = 0; for (int j = 0; j < strlen(sent); j++) { cout<<sent[j]; } char* word = strtok(sent, " "); while (word != nullptr) { int len = strlen(word); if (isPalindrome(word, len)) { counter++; } word = strtok(nullptr, " "); } cout << ": " << counter << endl; } return 0; }
Leave a Comment