Advertisement
Farjana_akter

Untitled

Jun 16th, 2020
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5.  
  6. int main()
  7. {
  8. string s;
  9. while(getline(cin,s))
  10. {
  11. int len=s.size();
  12. string ans="";
  13. int i,j,k;
  14. for(i=0; i<len; i++)
  15. {
  16. if(s[i]==' ' && s[i+1]==' ')
  17. {
  18. j=i;
  19. k=0;
  20. while(s[j]==' ')
  21. {
  22. j++;
  23. k++;
  24. }
  25. k--;
  26. while(k--)
  27. ans+=' ';
  28. i=j-1;
  29. }
  30. else if(s[i]==' ' && s[i+1]==',')
  31. {
  32. ans+=',';
  33. i++;
  34. }
  35. else if(s[i]==' ' && s[i+1]=='.')
  36. {
  37. ans+='.';
  38. i++;
  39. }
  40. else
  41. ans+=s[i];
  42. }
  43. cout<<ans<<endl;
  44. s.clear();
  45. }
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement