Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. char s[256];
  7. int n,ok=0,t=0,ap=0,lmax=0;
  8. cin.getline(s,sizeof(s));
  9. n=strlen(s);
  10. while(s[t]!=' ')
  11. t++;
  12. for(int i=0; i<n; i++)
  13. {
  14. ok=0,ap=0;
  15. if(s[i]==' ' || i+1==n)
  16. {
  17. if(i+1==n)
  18. i++;
  19. for(int j=t; j<i; j++)
  20. {
  21. if(isalpha(s[j]))
  22. ok=1;
  23. ap++;
  24. }
  25. if(ok==1)
  26. if(ap>lmax)
  27. lmax=ap;
  28. if(n!=i)
  29. {
  30. t=i;
  31. while(s[t]==' ')
  32. t++;
  33. }
  34. }
  35. }
  36. t=0;
  37. while(s[t]==' ')
  38. t++;
  39. for(int i=t; i<n; i++)
  40. {
  41. if(s[i]==' ' || i+1==n)
  42. {
  43. ok=0;
  44. if(i+1==n)
  45. i++;
  46. for(int j=t; j<i; j++)
  47. if(isalpha(s[j]))
  48. ok=1;
  49. if(ok==1)
  50. if(i-t==lmax)
  51. {
  52. for(int x=t,y=i-1; x<y; x++,y--)
  53. swap(s[x],s[y]);
  54. }
  55. if(n!=i)
  56. {
  57. t=i;
  58. while(s[t]==' ')
  59. t++;
  60. }
  61.  
  62. }
  63. }
  64. cout<<s;
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement