Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- using namespace std;
- int main()
- {
- char a[1000];
- cin.get(a,1000);
- int l=strlen(a);
- if(l>1)
- {
- int b[100];
- b[0]=0;
- int count=1;
- for(int i=0;i<l;i++)
- {
- if(a[i]==' ')
- {
- b[count]=i;
- count++;
- }
- }
- b[count]=l;
- count++;
- //ARRAY TO STORE INDEXES OF SPACES....
- char res[1000];
- int k=0;
- for(int i=count-2;i>=1;i--)
- {
- for(int j=b[i]+1;j<=b[i+1]-1;j++)
- {
- res[k]=a[j];
- k++;
- }
- res[k]=' ';
- k++;
- }
- if(k!=l)
- {
- for(int i=0;i<b[1];i++)
- {
- res[k]=a[i];
- k++;
- }
- }
- res[k]=' ';
- cout<<res<<endl;
- }
- else
- {
- cout<<a<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment