Advertisement
Muntean_Mihai

#975 Cuvinte2

Jan 22nd, 2021
974
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. //problema 975
  2. #include <iostream>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. char p[260];
  8. char cuvant[15];
  9. char favorit[15]="{";
  10. char sep[4]=" ,.";
  11.  
  12. int main()
  13. {
  14.     int i,j,n;
  15.     int pozitie_inceput, pozitie_sfarsit;
  16.     bool corect,exista=false;
  17.  
  18.     cin.getline(p,260);
  19.  
  20.     char *c=strtok(p,sep);
  21.     while (c!=NULL)
  22.     {
  23.         strcpy(cuvant,c);
  24.         n=strlen(cuvant);
  25.         corect=true;
  26.         for (i=0,j=n-1;i<n/2;i++,j--)
  27.         {
  28.             if (cuvant[i]!=cuvant[j])
  29.             {
  30.                 corect=false;
  31.                 break;
  32.             }
  33.         }
  34.  
  35.         if(corect==true)
  36.         {
  37.             exista=true;
  38.            // cout<<cuvant<<'\n';
  39.             if(cuvant[0]<=favorit[0] && strlen(cuvant)>strlen(favorit))
  40.             {
  41.                 strcpy(favorit,cuvant);
  42.             }
  43.         }
  44.         c=strtok(NULL,sep);
  45.     }
  46.     if(exista==true)
  47.         cout<<favorit;
  48.     else
  49.         cout<<"IMPOSIBIL";
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement