Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <sstream>
- #include <string>
- #include <vector>
- #include <list>
- #include <map>
- #include <set>
- #include <algorithm>
- using namespace std;
- struct CP{
- string meno;
- string ciel;
- string trieda;
- int valTrieda;
- int poradie;
- bool odisiel;
- };
- bool compare (CP a , CP b ){
- if(a.valTrieda < b.valTrieda)
- return true;
- else if(a.valTrieda == b.valTrieda && a.poradie < b.poradie)
- return true;
- else
- return false;
- }
- class CStation
- {
- public:
- CStation();
- ~CStation();
- void Arrive ( istream & is );
- list<string> Depart ( int cnt, const list<string> & dest ){
- int pocet = 0;
- list <string> zoznam;
- zoznam.clear();
- list<string>::const_iterator zaciatok = dest.begin();
- list<string>::const_iterator koniec = dest.end();
- /* for(int i = 0; i < ludia.size(); i++){
- cout << ludia[i].meno << "::::" << ludia[i].ciel << ":::" << ludia[i].trieda << "::::" << ludia[i].poradie << endl;
- }
- cout << "==========" << endl;
- */
- for(int i = 0; i < ludia.size(); i++){
- for(zaciatok = dest.begin(); zaciatok != koniec; zaciatok++){
- if(ludia[i].ciel == *zaciatok && pocet < cnt && ludia[i].odisiel == false){
- zoznam.push_back(ludia[i].meno);
- ludia[i].ciel = true;
- pocet++;
- }
- }
- }
- return zoznam;
- }
- private:
- vector<CP> ludia;
- };
- CStation::CStation(){
- }
- CStation::~CStation(){
- }
- void showList ( const list<string> & l )
- {
- for ( list<string>::const_iterator it = l . begin (); it != l . end (); ++it )
- cout << *it << endl;
- }
- void CStation::Arrive(istream& is){
- string line, meno, ciel, trieda, tmp_string;
- size_t pos;
- int poradie = 1;
- int valTrieda = 0;
- while(getline(is, line)){
- pos = line.find(";");
- tmp_string = line.substr(pos+1);
- meno = line.substr(0,pos);
- pos = tmp_string.find(";");
- ciel = tmp_string.substr(0, pos);
- trieda = tmp_string.substr(pos+1);
- if(trieda == "First class") valTrieda = 1;
- else if(trieda == "Business class") valTrieda = 2;
- else if(trieda == "Premium economy") valTrieda = 3;
- else if(trieda == "Economy class") valTrieda = 4;
- else if(trieda == " Steerage") valTrieda = 5;
- CP tmp = {
- meno,
- ciel,
- trieda,
- valTrieda,
- poradie,
- false
- };
- ludia.push_back(tmp);
- poradie++;
- }
- sort(ludia.begin(), ludia.end(), compare);
- }
- /*
- *
- */
- int main(int argc, char** argv) {
- CStation s;
- list<string> dest;
- istringstream iss;
- iss . clear ();
- iss . str (
- "John;Tidmouth;Economy class\n"
- "Peter;Tidmouth;Premium economy\n"
- "Laura;Knapford;Steerage\n"
- "Thomas;Knapford;Business class\n"
- "Anne;Maron;Premium economy\n"
- "Joe;Maron;First class\n"
- "James;Suddery;First class\n"
- "Edward;Suddery;Premium economy\n"
- );
- s . Arrive ( iss );
- dest . clear ();
- dest . push_back ( "Tidmouth" );
- dest . push_back ( "Knapford" );
- dest . push_back ( "Brendam Docks" );
- showList ( s . Depart ( 2, dest ) );
- /*
- ---8<---8<---8<---8<---8<---8<---
- Thomas
- Peter
- ---8<---8<---8<---8<---8<---8<---
- */
- cout << "==========" << endl;
- iss . clear ();
- iss . str (
- "William;Great Waterton;Steerage\n"
- "Elisabeth;Great Waterton;Business class\n"
- "Roy;Suddery;Steerage"
- );
- s . Arrive ( iss );
- dest . clear ();
- dest . push_back ( "Suddery" );
- dest . push_back ( "Great Waterton" );
- dest . push_back ( "Tidmouth" );
- dest . push_back ( "Knapford" );
- showList ( s . Depart ( 10, dest ) );
- /*
- ---8<---8<---8<---8<---8<---8<---
- Elisabeth
- Edward
- John
- Laura
- William
- Roy
- ---8<---8<---8<---8<---8<---8<---
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment