+ 5

[ASSIGNMENT] String swap

Write a code where you swap the value of two strings without using a third variable. Note:codes involving conversion of string to ASCII values are disqualified

8th Apr 2018, 6:58 PM
᠌᠌Code X
᠌᠌Code X - avatar
11 Answers
9th Apr 2018, 1:22 AM
᠌᠌Code X
᠌᠌Code X - avatar
+ 20
Swap two strings with and without third variable && show the time spent to solving the task! 😄👍😉 https://code.sololearn.com/c24Tb04EO0PQ/?ref=app
8th Apr 2018, 8:43 PM
Danijel Ivanović
Danijel Ivanović - avatar
8th Apr 2018, 7:38 PM
Vishal Pal❄️⚛️
Vishal Pal❄️⚛️ - avatar
+ 9
I did it two different ways. https://code.sololearn.com/cIU5mT1NJpqw
8th Apr 2018, 8:42 PM
John Wells
John Wells - avatar
+ 6
python's solution is easy AF!!
9th Apr 2018, 1:22 AM
Favour
Favour - avatar
+ 4
There's a built-in swap() function in C++. Time to solve ~1min: https://code.sololearn.com/cPgo477jb414/?ref=app In C it would have been more of a challenge.
9th Apr 2018, 10:34 PM
non
+ 3
Here's my solution using XOR. Programmed in C: https://code.sololearn.com/c1SPQxq59Jh0/#c I couldn't work out what you meant by not converting to ASCII values! The strings in C are already ASCII based arrays! Anyway, no conversion occurs.
8th Apr 2018, 8:33 PM
Emma
+ 3
yes favour I know,its pretty much too easy
9th Apr 2018, 1:26 AM
᠌᠌Code X
᠌᠌Code X - avatar
+ 2
I still love the Python answer though, as it's a reminder that a complex task in one programming language can be easy in another, and vice versa 😂
9th Apr 2018, 1:27 AM
Emma
+ 2
in c++ you can use function strrev() which comes under string.h header file
9th Apr 2018, 3:28 PM
Tony Stark
Tony Stark - avatar
+ 1
nonzyro Yes, I think some challenges, need to specify the language. Example, if the challenge was to create a list library, it would be much harder in C than Java etc!
9th Apr 2018, 10:36 PM
Emma