fork(12) download
  1. #include <cstring>
  2. #include <iostream>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main() {
  7. string a="qwertyboy",b="";
  8. /*3 line method*/
  9. for(int i=a.size();i>=0;i--)
  10. b+=a[i];
  11. a=b;
  12. cout<<a<<'\n';
  13. a="qwertyboy";
  14.  
  15. // 2- line method
  16.  
  17. for(int i=0,j=a.size()-1;i<j;i++,j--){
  18. swap(a[i],a[j]);
  19. }
  20. cout<<a<<'\n';
  21. a="qwertyboy";
  22. // 1-line method
  23. reverse(a.begin(),a.end());
  24. cout<<a<<'\n';
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
yobytrewq
yobytrewq
yobytrewq