DMG

Palindrom

DMG
Jul 2nd, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. main()
  4. {
  5.       string s, k;
  6.       int n; bool p;
  7.      
  8.       getline (cin, s);
  9.      
  10.       // Dio koji brise razmake i pretvara cio string u mala slova
  11.       for (int i=0; i<s.length(); i++)
  12.       {
  13.           if (s[i]!=' ')
  14.           {
  15.                       if (s[i] < 91)
  16.                       {
  17.                                s[i] = s[i] + 32;
  18.                                k = k + s[i];
  19.                       }
  20.                       else
  21.                                k = k + s[i];
  22.           }
  23.       }
  24.      
  25.       n = k.length();
  26.      
  27.       p = true;
  28.       for (int i=0; i<n/2; i++)
  29.       if (k[i] != k[n-i-1])
  30.       p = false;
  31.      
  32.       if (p==true)
  33.       cout << "Jeste palindrom! " << endl;
  34.       else
  35.       cout << "Nije palindrom!  " << endl;
  36.      
  37.       // cout << k;
  38.      
  39.       system ("PAUSE");
  40. }
Advertisement
Add Comment
Please, Sign In to add comment