fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. string s="hello world 123";
  6. cin>>s;
  7. stack<string>st;
  8. string str="";
  9. for(int i=0;i<s.length();i++){
  10. if(s[i]==' '){
  11. st.push(str);
  12. str="";
  13. }
  14. else str+=s[i];
  15. }
  16. string ans="";
  17. while(st.size()!=1){
  18. ans+=st.top()+" ";
  19. st.pop();
  20. }
  21. ans+=st.top();
  22. cout<<ans;
  23. // your code goes here
  24. return 0;
  25. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
world hello