Advertisement
a53

InversMax

a53
Dec 3rd, 2018
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. char cuv[256][256];
  5. int LitD[256],Sp[256];
  6.  
  7. bool cuvant(int i)
  8. {
  9. bool ok=false;
  10. for(int j=0;j<(int)strlen(cuv[i]);++j)
  11. if(isalpha(cuv[i][j]))
  12. {
  13. ok=true;
  14. break;
  15. }
  16. return ok;
  17. }
  18.  
  19. void invers(int i)
  20. {
  21. if(cuvant(i))
  22. for(int j=0;j<LitD[i]/2;++j)
  23. swap(cuv[i][j],cuv[i][LitD[i]-1-j]);
  24. }
  25.  
  26. int main()
  27. {
  28. char s[256],*p,separator[]=" ";
  29. cin.getline(s,256);
  30. int n=0,k=0;
  31. while(k<(int)strlen(s))
  32. {
  33. if(s[k]==' ')
  34. {
  35. Sp[n]=1;
  36. while(s[++k]==' ')
  37. ++Sp[n];
  38. ++n;
  39. }
  40. ++k;
  41. }
  42. p=s;
  43. p=strtok(p,separator);
  44. int MAX=0;
  45. n=0;
  46. while(p)
  47. {
  48. strcpy(cuv[n],p);
  49. if(cuvant(n))
  50. LitD[n]=strlen(cuv[n]);
  51. else
  52. LitD[n]=0;
  53. if(LitD[n]>MAX)
  54. MAX=LitD[n];
  55. ++n,p=strtok(NULL,separator);
  56. }
  57. for(int i=0;i<n;++i)
  58. {
  59. if(LitD[i]==MAX)
  60. invers(i);
  61. if(s[0]==' ')
  62. {
  63. for(int k=1;k<=Sp[i];++k)
  64. cout<<' ';
  65. cout<<cuv[i];
  66. }
  67. else
  68. {
  69. cout<<cuv[i];
  70. for(int k=1;k<=Sp[i];++k)
  71. cout<<' ';
  72. }
  73. }
  74. cout<<'\n';
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement