fork(1) download
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. void reverse( char *s )
  5. {
  6. if ( !s )
  7. return;
  8.  
  9. char *e = s + strlen( s ) - 1;
  10. while ( s < e )
  11. {
  12. *e ^= *s;
  13. *s ^= *e;
  14. *e-- ^= *s++;
  15. }
  16. }
  17. int main() {
  18. // your code goes here
  19. char* s1 = "123";
  20. char* s2 = "";
  21. char s3[4];
  22. memcpy(s3, s1, strlen(s1)+1);
  23.  
  24. std::cout << s3 << " - " << std::endl;
  25. reverse(s3);
  26. std::cout << s3 << std::endl;
  27.  
  28. memcpy(s3, s2, strlen(s2)+1);
  29. std::cout << s3 << " - " << std::endl;
  30. reverse(s2);
  31. std::cout << s3 << std::endl;
  32. return 0;
  33. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
123 - 
321
 -