Advertisement
YasserZ

Mother Bear

Mar 5th, 2012
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include<iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main ()
  6. {
  7.     string line;
  8.     bool palindrome = false;
  9.     while(getline(cin, line))
  10.     {
  11.         if (line == "DONE")
  12.             break;
  13.         for(int i = 0; i < line.size(); i++)
  14.         {
  15.             if((line[i] == 46) || (line[i] == 44) || (line[i] == 33) || (line[i] == 63) || (line[i] == 32))
  16.             {
  17.                 line.erase(i, 1);
  18.                 i--;
  19.             }
  20.         }
  21.         for(int j = 0; j < line.size(); j++)
  22.         {
  23.             int length = line.size() - 1;
  24.             if((line[j] == line[length - j]) || (line[j] + 32 == line[length - j]) || (line[j] - 32 == line[length - j]))
  25.                 palindrome = true;
  26.             else
  27.             {
  28.                 palindrome = false;
  29.                 break;
  30.             }
  31.         }
  32.         if(palindrome == true)
  33.             cout << "You won't be eaten!" << endl;
  34.         else
  35.             cout << "Uh oh.." << endl;
  36.         palindrome = false;
  37.     }
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement