Advertisement
nicuvlad76

Untitled

Nov 13th, 2020
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <fstream>
  4. #define N 301
  5. using namespace std;
  6. char s[N], pmax[N];
  7. bool ok;
  8. void elimin(char s[])
  9. {
  10.    char t[N] ; int k=0;
  11.    for(int i=0;s[i]; i++)
  12.     if(s[i]>='a'&& s[i]<='z') t[k++]=s[i];
  13.    t[k]=NULL;
  14.    strcpy(s,t);
  15. }
  16.  
  17. bool palindrom(char s[])
  18. {
  19.     int n=strlen(s);
  20.     for(int i=0; i<n/2;i++)
  21.         if(s[i]!=s[n-i-1])return 0;
  22.     return 1;
  23. }
  24.  
  25. void Citire()
  26. {
  27.     //ifstream cin("date.in");
  28.    while(cin>>s)
  29.    {
  30.        elimin(s);
  31.        if(palindrom(s))
  32.        {
  33.            if(ok==0) strcpy(pmax,s);
  34.            else
  35.              if(strcmp(pmax,s)>0)strcpy(pmax,s);
  36.          ok=1;
  37.        }
  38.    }
  39.    if(ok!=0)cout<<pmax;
  40.    else cout<<"IMPOSIBIL";
  41. }
  42.  
  43. int main()
  44. {
  45.    Citire();
  46.     return 0;
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement