0
Character Arithmetic Problem
I was testing my C++ knowledge in Challenge mode when I came across this problem: #include <iostream> using namespace std; char*f(char* const s, int n){ int i = 0; n--; while(i<n){ s[i]+=s[n]; s[n]= s[i] - s[n]; s[i] -=s[n]; i++; --n; } return s; } int main(){ char s[] = "desrever"; cout << f(s, 6+2); return 0; } What's the trick here? It went by so fast I couldn't solve it in time, so there must be something REALLY obvious that I'm missing. Starting from the top, I need to add s[i]+=s[n], or d+=r. Was I just expected to know the numeric values of the letters or is there something else. Any help would be appreciated.
3 Answers
0
Thanks @-swim-, I would have never figured that out on my own. I still have a lot left to learn....