Advertisement
Krakenos

Untitled

Mar 11th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cctype>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     char *word = new char[200];
  9.     int n;
  10.     bool pal=true;
  11.     cin >> n;
  12.     cin.getline(word, 200);
  13.     for (int i = 0; i < n; i++){
  14.         cin.getline(word, 200);
  15.         int w_len = strlen(word);
  16.         pal = true;
  17.         for (int j = 0, k = w_len - 2; j < (w_len - 1) / 2 && pal; j++, k--){
  18.             if(tolower(word[j]) != tolower(word[k])){
  19.                 pal = false;
  20.                 break;
  21.             }
  22.         }
  23.         if(pal){
  24.             for (int j = 0; j < w_len - 1; j++){
  25.                 cout << word[j];
  26.             }
  27.             cout << " - to jest palindrom" << endl;
  28.         }
  29.         else{
  30.             for (int j = 0; j < w_len - 1; j++){
  31.                 cout << word[j];
  32.             }
  33.             cout << " - to nie jest palindrom" << endl;
  34.         }
  35.     }
  36.     delete[] word;
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement