I think it's exchanging the first letters of the words.
When we exchange, or 'swap' two variables, often we create a temporary variable to hold one, then we assign the other to the position of the first and copy over the temp to its new location.
e.g.
1 2 3 4 5
char a = 'a', b = 'b', temp;
temp = b;
b = a;
a = temp;
I hope this is enough of an idea. Unless you don't know how to input words?
That was quite amazing, but only testament to how obvious the answer was; hombakazij I hope you're very tired or something, because really you have to at least try and understand what we tell you and make use of it rather than just be spoon-fed, or you'll learn nothing from this!
@Veltas: I am going to really try my best, am new in programming but that's not an excuse for me to be spoon-fed. And i do understand the program now i even worked out the output on a paper trying to understand it, and now i get it. thanks a lot.
"Knowing how to swap" is knowing how to use std::swap(). If you think about it in terms of assignments, you may think that swapping two strings or two vectors involves copying.
I think it's easier to understand std::swap than it is to understand which variable to stick in a temp variable, order of swapping etc. I agree that beginners should do this themselves just to understand it, but I also say they should get involved in the STL as soon as possible, as opposed to the old "Let's learn the C stuff with C++"
I'm sorry but in my early C++ days I clinged to all the rules given to me and tried to work with the C++ I could in order to produce what I needed. If you had introduced specific STL functions to me I would have complained it was too much information for a beginner and said that I'd learn to use specific functions when it came to it but for now the pure basics were hard enough.
And if you had shown me swap, I wouldn't have seen it as easier to understand. For one thing it either requires you have a good idea of how functions work, or you're prepared to blindly do whatever they ask of you without understanding; which in my books isn't learning, or even helpful if there's another way that will give you more experience with the core programming functionality.
@Veltas When you don't know what you're doing and why, it's useless to learn how. Only after learning how to *use* basic C++ components - vector, swap, cout, etc, it makes any sense to start implementing your own classes and functions.
I'm not an expert in C++ but I'm going to side with Veltas on this one. Cubbi, you say that one should learn how to use basic C++ components like swap. However, I think the solution Veltas and Moschops show above is much more basic than this swap function, indeed, the swap function most likely has a similar functionality to what they did.
I believe that it is much better to first learn how to solve a problem using the very basics, and then at a later time learn the included C++ functions like swap. This way you build your problem solving skills, so in the event that you run into a problem for which you cannot think of a suitable built-in function to solve, you can do it yourself having a solid understanding of the essential basics. The built-in functions, while a valuable and efficient tool for more versed C++ programmers, should be used sparingly by beginners.