// StrAlgoDemo.cpp

#include <iostream>
#include <string>
#include <utility>

using namespace std;

string trim_right( const string& s, const string& t = " ")
{
  string source = s;
  return source.erase( source.find_last_not_of( t ) + 1 ) ;
}

string trim_left( const string& s, const string& t = " ")
{
  string source = s;
  return source.erase( 0, source.find_first_not_of( t ) ) ;
}

pair<string, string> split_name( const string& full_name )
{
  string s = trim_left(trim_right(full_name));
  string::size_type n = s.find_last_of(" ");
  if ( n == string::npos ) {
    return make_pair("", s);
  }
  else {
    return make_pair(s.substr(0,n), s.substr(n+1,s.size()));
  }
}

void doit( const string& name )
{
  pair<string,string> names;

  names = split_name(name);
  cout << "\"" << names.second;
  if ( names.first.size() > 0 ) {
    cout << ", " << names.first;
  }
  cout << "\"" << endl;
}

int main()
{
  doit("Francielli Gomes");
  doit("Josué Andrade Gomes");
  doit("João Victor Andrade Gomes");
  doit("Francisco Andrade Gomes");
}