rakcode1998

Untitled

Feb 18th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     char a[1000];
  10.     cin.get(a,1000);
  11.     int l=strlen(a);
  12.  
  13. if(l>1)
  14. {
  15.     int b[100];
  16.     b[0]=0;
  17.  
  18.     int count=1;
  19.  
  20.     for(int i=0;i<l;i++)
  21.     {
  22.         if(a[i]==' ')
  23.         {
  24.             b[count]=i;
  25.             count++;
  26.         }
  27.     }
  28.  
  29.     b[count]=l;
  30.     count++;
  31.     //ARRAY TO STORE INDEXES OF SPACES....
  32.  
  33.     char res[1000];
  34.     int k=0;
  35.  
  36.     for(int i=count-2;i>=1;i--)
  37.     {
  38.         for(int j=b[i]+1;j<=b[i+1]-1;j++)
  39.         {
  40.             res[k]=a[j];
  41.             k++;
  42.         }
  43.  
  44.         res[k]=' ';
  45.         k++;
  46.     }
  47.  
  48.  
  49.     if(k!=l)
  50.     {
  51.         for(int i=0;i<b[1];i++)
  52.         {
  53.             res[k]=a[i];
  54.             k++;
  55.         }
  56.     }
  57.  
  58.     res[k]=' ';
  59.  
  60.     cout<<res<<endl;
  61. }
  62.  
  63.     else
  64.     {
  65.         cout<<a<<endl;
  66.     }
  67.  
  68.     return 0;
  69. }
Add Comment
Please, Sign In to add comment