sandeep03edu

Remove trailing and forward spaces

Jun 29th, 2022
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. int main() {
  6.     // your code goes here
  7.     string str = " ah  na ";
  8.     char space = ' ';
  9.    
  10.     size_t found = str.find(space);
  11.     while(found!=string::npos){
  12.         if(found==0 || found==str.length()-1){
  13.             int pos =found;
  14.             str.erase(pos, 1);
  15.         }
  16.         found = str.find(space, found+1);
  17.     }
  18.    
  19.     cout<<str<<endl;
  20.     return 0;
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment