knakul853

Untitled

Jun 19th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. /**
  2. knakul853
  3. **/
  4. class Solution {
  5. public:
  6.     string reverseWords(string s) {
  7.        
  8.         int n = (int)s.size();
  9.        
  10.         istringstream in(s);
  11.         s="";
  12.         string word;
  13.         while( in >> word )
  14.         {
  15.             reverse(word.begin(), word.end());
  16.            
  17.             s+=word + " ";
  18.         }
  19.        
  20.         int m = s.size();
  21.        
  22.         return s.substr(0, m-1);
  23.      
  24.     }
  25. };
Add Comment
Please, Sign In to add comment