Fragen im Vorstellungsgespräch bei Bloomberg L.P.: Write a function to convert F... | Glassdoor.de

Frage im Vorstellungsgespräch

Financial Software Developer Intern-Vorstellungsgespräch(Studentischer Bewerber) New York, NY (Vereinigte Staaten von Amerika)

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

  Name, First Name.
Antwort

Antwort im Vorstellungsgespräch

3 Antworten

0

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.

Bewerber im Vorstellungsgespräch am 11.03.2010
1

#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;

}

Anonym am 19.05.2010
0

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!

Anonym am 19.05.2010

Antwort oder Kommentar posten

Um dies zu kommentieren, bitte anmelden oder Konto anlegen.