fork(4) download
  1. #include <iostream>
  2. #include <stack>
  3. using namespace std;
  4.  
  5. int main() {
  6. stack<char> stack;
  7. cout << "Enter a string (max 10 letters): ";
  8. char string[10];
  9. cin.getline(string, 10);
  10. int size = cin.gcount();
  11.  
  12. for (int t = 0; t < (size >> 1); ++t)
  13. stack.push(string[t]);
  14.  
  15. for (int t = ~size & 1 ? size >> 1 : -~(size >> 1); t < size; ++t) {
  16. char top = stack.top();
  17. stack.pop();
  18. if (top != string[t]) {
  19. cout << "The string is not palindrome\n";
  20. break;
  21. }
  22. }
  23.  
  24. if (stack.empty())
  25. cout << "The string is palindrome\n";
  26. return 0;
  27. }
Success #stdin #stdout 0s 3480KB
stdin
raceca
stdout
Enter a string (max 10 letters): The string is not palindrome