#include <iostream>
#include <string.h>
void reverse( char *s )
{
if ( !s )
return;
char *e = s + strlen( s ) - 1;
while ( s < e )
{
*e ^= *s;
*s ^= *e;
*e-- ^= *s++;
}
}
int main() {
// your code goes here
char* s1 = "123";
char* s2 = "";
char s3[4];
memcpy(s3, s1, strlen(s1)+1);
std::cout << s3 << " - " << std::endl;
reverse(s3);
std::cout << s3 << std::endl;
memcpy(s3, s2, strlen(s2)+1);
std::cout << s3 << " - " << std::endl;
reverse(s2);
std::cout << s3 << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nLmg+Cgp2b2lkIHJldmVyc2UoIGNoYXIgKnMgKQp7CiAgICBpZiAoICFzICkKICAgICAgICByZXR1cm47CgogICAgY2hhciAqZSA9IHMgKyBzdHJsZW4oIHMgKSAtIDE7CiAgICB3aGlsZSAoIHMgPCBlICkKICAgIHsKICAgICAgICAqZSBePSAqczsKICAgICAgICAqcyBePSAqZTsKICAgICAgICAqZS0tIF49ICpzKys7CiAgICB9Cn0KaW50IG1haW4oKSB7CgkvLyB5b3VyIGNvZGUgZ29lcyBoZXJlCgljaGFyKiBzMSA9ICIxMjMiOwoJY2hhciogczIgPSAiIjsKICAgIGNoYXIgczNbNF07Cm1lbWNweShzMywgczEsIHN0cmxlbihzMSkrMSk7CgkKCXN0ZDo6Y291dCA8PCBzMyA8PCAiIC0gIiA8PCBzdGQ6OmVuZGw7CglyZXZlcnNlKHMzKTsKCXN0ZDo6Y291dCA8PCBzMyA8PCBzdGQ6OmVuZGw7CgkKbWVtY3B5KHMzLCBzMiwgc3RybGVuKHMyKSsxKTsKCXN0ZDo6Y291dCA8PCBzMyA8PCAiIC0gIiA8PCBzdGQ6OmVuZGw7CglyZXZlcnNlKHMyKTsKCXN0ZDo6Y291dCA8PCBzMyA8PCBzdGQ6OmVuZGw7CglyZXR1cm4gMDsKfQ==