diff --git a/main.cpp b/main.cpp index 70a5da7..8419513 100644 --- a/main.cpp +++ b/main.cpp @@ -100,9 +100,12 @@ bool isValidPlayer(char c) { } void swapChar(char &a, char &b) { - char temp = a; - a = b; - b = temp; + if (a == b) { + return; + } + a ^= b; + b ^= a; + a ^= b; } // Recursively reverse a string @@ -112,6 +115,7 @@ void reverseString(string &str, int start, int end) { } swapChar(str[start], str[end]); + reverseString(str, start + 1, end - 1); }