Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- char s[260],cuv[260][12];
- int n;
- int pal(char s[])
- {
- int i,j;
- i=0;
- j=strlen(s)-1;
- while(i<j)
- {
- if(s[i]==s[j])
- {
- i++;
- j--;
- }
- else
- return 0;
- }
- return 1;
- }
- int main()
- {
- char*p,sep[]=" ,.", sol[12];
- int i;
- strcpy(sol, "zzzzzzzzzz");
- cin.getline(s,256);
- p=strtok(s,sep);
- while(p!=NULL)
- {
- n++;
- strcpy(cuv[n],p);
- p=strtok(NULL,sep);
- }
- for(i=1;i<=n;i++)
- {
- if(pal(cuv[i]))
- {
- if (strcmp(cuv[i],sol)<0)
- strcpy(sol,cuv[i]);
- }
- }
- if(strcmp(sol,"zzzzzzzzzz")==0)
- cout<<"IMPOSIBIL";
- else
- cout<<sol;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement