diff --git a/main.cpp b/main.cpp index 2722994..fa70871 100644 --- a/main.cpp +++ b/main.cpp @@ -99,6 +99,23 @@ bool isValidPlayer(char c) { return c >= 'A' && c <= 'Z' && c != 'X'; } +void swapChar(char &a, char &b) { + char temp = a; + a = b; + b = temp; +} + +// Recursively reverse a string +void reverseString(string &str, int start, int end) { + if (start >= end) { + return; + } + + swapChar(str[start], str[end]); + reverseString(str, start + 1, end - 1); +} + + string toString(int x) { if (!x) return "0"; @@ -107,7 +124,7 @@ string toString(int x) { result.push_back(x % 10 + '0'); x /= 10; } - reverse(all(result)); + reverseString(result, 0, result.size() - 1); return result; }