fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstring>
  4. using namespace std;
  5. int ac=0;
  6. void reverseString(string a,int count)
  7. {
  8. if(count==a.length())
  9. {
  10. for(int g=ac-1;g<a.length();g++)
  11. cout<<a[g];
  12. }
  13. else if(a[count]!=' '&&count<a.length())
  14. {
  15. ac++;
  16. reverseString(a,count+1);
  17. }
  18. else if(a[count]==' ')
  19. {
  20. reverseString(a,count+1);
  21. ac-=count;
  22.  
  23. for(int g=ac+1;g<count;g++)
  24. cout<<a[g];
  25. if(ac!=-1)
  26. cout<<" ";
  27. }
  28. }
  29. int main()
  30. {
  31. string a,b;
  32. a="How are you";
  33. reverseString(a,0);
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0.01s 2812KB
stdin
Standard input is empty
stdout
you are How