Skip to content

Commit

Permalink
exercise 450
Browse files Browse the repository at this point in the history
  • Loading branch information
gbordignondaitan committed Nov 1, 2018
1 parent 6a6566b commit 03f199d
Showing 1 changed file with 123 additions and 0 deletions.
123 changes: 123 additions & 0 deletions 2/2/450.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/**
* Guilherme de Novais Bordignon - UVA Judge Online Solution
*
* 450 - Little Black Book
**/

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <string>
#include <iomanip>


using namespace std;

class Person
{
string title;
string firstName;
string familyName;
string address;
string homePhone;
string workPhone;
string campusBox;
string department;

public:
Person(string title, string firstName, string familyName,
string address, string homePhone, string workPhone,
string campusBox, string department)
: title(title), firstName(firstName), familyName(familyName),
address(address), homePhone(homePhone), workPhone(workPhone),
campusBox(campusBox), department(department)
{ }

string to_string() const
{
string str = "----------------------------------------\n";

str += title + " " + firstName + " " + familyName + "\n";
str += address + "\n";
str += "Department: " + department + "\n";
str += "Home Phone: " + homePhone + "\n";
str += "Work Phone: " + workPhone + "\n";
str += "Campus Box: " + campusBox + "\n";
return str;
}

bool operator() (const Person &p2) const
{
return p2.familyName != familyName ?
familyName < p2.familyName :
firstName < p2.firstName;
}

bool operator< (const Person &p2) const
{
return p2.familyName != familyName ?
familyName < p2.familyName :
firstName < p2.firstName;
}
};

int main()
{
int k = 0;
int N;
string output = "";
string line;
string department;
set<Person> people;

output.reserve(500000);
cin >> N;
cin.ignore();

while(k++ < N && !cin.eof())
{
string title, firstName, familyName, address, home, work, campus;
getline(cin, department);

while (true)
{
getline(cin, line);
if (line == "") break;

stringstream ss(line);

getline(ss, title,',');
getline(ss, firstName,',');
getline(ss, familyName,',');
getline(ss, address,',');
getline(ss, home,',');
getline(ss, work,',');
getline(ss, campus);

people.insert(
Person(title, firstName, familyName, address,
home, work, campus, department));
}

for (auto person = people.begin();
person != people.end();
person++)
{
output += person->to_string();
}
}

printf("%s", output.c_str());

return(0);
}

0 comments on commit 03f199d

Please sign in to comment.