Input
"the sky is blue"
Expected Output
"blue is sky the"
My Output
"blue is sky "
I am unable to point out the error in the code.
Here is the code :
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s = "the sky is blue";
    reverse(s.begin(),s.end());
    stack<char> t;
    for(int i = 0;i < s.length();i++){
        if(s[i] != ' '){
            t.push(s[i]);
        }
        else{
            while(!t.empty()){
                cout << t.top();
                t.pop();
            }
            cout << " ";
        }
    }
    return 0;
}
 
     
     
    