Pregunta de entrevista de Bloomberg

Write a function to convert First Name, Last Name to Last Name, First Name.

Respuestas de entrevistas

Anónimo

20 de may de 2010

#include using namespace std; void swap (string * first, string * last); int main () { string first, last; cout > first; cout > last; swap (&first, &last); cout << "Swapping your first and last name." << endl; cout << "Your first name is now " << first << "." << endl; cout << "Your last name is now " << last << "." << endl; return 0; } void swap (string * pfirst, string * plast) { string temp = *pfirst; *pfirst = *plast; *plast = temp; }

1

Anónimo

20 de may de 2010

To be precise I forgot to add: // above swap (&first, &last) cout << "Your name is " << first << ", " << last << endl; // replace above return 0; cout << Your name is now " << first << ", " << last << endl; You don't have to pass by reference, you could have just used the swap function to reverse the order of the first and last name, but this is more impressive for an interview!

Anónimo

12 de mar de 2010

You can do it inplace my swapping the last and first char and then shifting the start index and rest string by one place each time.