Guest User

Untitled

a guest
May 17th, 2014
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <sstream>
  4. #include <string>
  5. #include <vector>
  6. #include <list>
  7. #include <map>
  8. #include <set>
  9. #include <algorithm>
  10. using namespace std;
  11.  
  12.  
  13. struct CP{
  14.     string meno;
  15.     string ciel;
  16.     string trieda;
  17.     int valTrieda;
  18.     int poradie;
  19.     bool odisiel;
  20. };
  21.  
  22.  
  23. bool compare (CP a , CP b ){
  24.     if(a.valTrieda < b.valTrieda)
  25.         return true;
  26.     else if(a.valTrieda == b.valTrieda && a.poradie < b.poradie)
  27.         return true;
  28.     else
  29.         return false;
  30. }
  31.  
  32.  
  33. class CStation
  34.  {
  35.    public:
  36.        CStation();
  37.        ~CStation();
  38.     void           Arrive ( istream & is );
  39.     list<string>   Depart ( int cnt, const list<string> & dest ){
  40.         int pocet = 0;
  41.        
  42.         list <string> zoznam;
  43.         zoznam.clear();
  44.         list<string>::const_iterator zaciatok = dest.begin();
  45.         list<string>::const_iterator koniec = dest.end();
  46.        
  47.     /* for(int i = 0; i < ludia.size(); i++){
  48.          cout << ludia[i].meno << "::::" << ludia[i].ciel << ":::" << ludia[i].trieda << "::::" << ludia[i].poradie << endl;
  49.      }
  50.        
  51.      cout << "==========" << endl;
  52.        
  53.      
  54.        */
  55.        
  56.        
  57.        
  58.         for(int i = 0; i < ludia.size(); i++){
  59.             for(zaciatok = dest.begin(); zaciatok != koniec; zaciatok++){
  60.                 if(ludia[i].ciel == *zaciatok && pocet < cnt && ludia[i].odisiel == false){
  61.                     zoznam.push_back(ludia[i].meno);
  62.                     ludia[i].ciel = true;
  63.                     pocet++;
  64.                 }
  65.             }
  66.         }
  67.        
  68.        
  69.       return zoznam;  
  70.     }
  71.    private:
  72.        vector<CP> ludia;
  73.  };
  74.  
  75.  CStation::CStation(){
  76.      
  77.  }
  78.  
  79.  CStation::~CStation(){
  80.      
  81.  }
  82.  
  83.  
  84. void showList ( const list<string> & l )
  85.  {
  86.    for ( list<string>::const_iterator it = l . begin (); it != l . end (); ++it )
  87.     cout << *it << endl;
  88.  }
  89.  
  90. void CStation::Arrive(istream& is){
  91.     string line, meno, ciel, trieda, tmp_string;
  92.     size_t pos;
  93.     int poradie = 1;
  94.     int valTrieda = 0;
  95.    
  96.     while(getline(is, line)){
  97.         pos = line.find(";");
  98.         tmp_string = line.substr(pos+1);
  99.         meno = line.substr(0,pos);
  100.         pos = tmp_string.find(";");
  101.         ciel = tmp_string.substr(0, pos);
  102.         trieda = tmp_string.substr(pos+1);
  103.        
  104.        
  105.         if(trieda == "First class") valTrieda = 1;
  106.         else if(trieda == "Business class") valTrieda = 2;
  107.         else if(trieda == "Premium economy") valTrieda = 3;
  108.         else if(trieda == "Economy class") valTrieda = 4;
  109.         else if(trieda == " Steerage") valTrieda = 5;
  110.        
  111.        
  112.        
  113.         CP tmp = {
  114.             meno,
  115.             ciel,
  116.             trieda,
  117.             valTrieda,
  118.             poradie,
  119.             false
  120.         };
  121.        
  122.         ludia.push_back(tmp);
  123.        
  124.         poradie++;
  125.     }
  126.    
  127.     sort(ludia.begin(), ludia.end(), compare);
  128.  
  129.    
  130. }
  131.  
  132.  
  133. /*
  134.  *
  135.  */
  136. int main(int argc, char** argv) {
  137.  
  138. CStation     s;
  139. list<string> dest;
  140. istringstream iss;
  141.  
  142. iss . clear ();
  143. iss . str (
  144.    "John;Tidmouth;Economy class\n"
  145.    "Peter;Tidmouth;Premium economy\n"
  146.    "Laura;Knapford;Steerage\n"
  147.    "Thomas;Knapford;Business class\n"
  148.    "Anne;Maron;Premium economy\n"
  149.    "Joe;Maron;First class\n"
  150.    "James;Suddery;First class\n"
  151.    "Edward;Suddery;Premium economy\n"
  152.  );
  153. s . Arrive ( iss );
  154. dest . clear ();
  155. dest . push_back ( "Tidmouth" );
  156. dest . push_back ( "Knapford" );
  157. dest . push_back ( "Brendam Docks" );
  158. showList ( s . Depart ( 2, dest ) );
  159. /*
  160. ---8<---8<---8<---8<---8<---8<---
  161. Thomas
  162. Peter
  163. ---8<---8<---8<---8<---8<---8<---
  164. */    
  165.  cout << "==========" << endl;
  166.  
  167.  iss . clear ();
  168. iss . str (
  169.    "William;Great Waterton;Steerage\n"
  170.    "Elisabeth;Great Waterton;Business class\n"
  171.    "Roy;Suddery;Steerage"
  172.  );
  173. s . Arrive ( iss );
  174. dest . clear ();
  175. dest . push_back ( "Suddery" );
  176. dest . push_back ( "Great Waterton" );
  177. dest . push_back ( "Tidmouth" );
  178. dest . push_back ( "Knapford" );
  179. showList ( s . Depart ( 10, dest ) );
  180. /*
  181. ---8<---8<---8<---8<---8<---8<---
  182. Elisabeth
  183. Edward
  184. John
  185. Laura
  186. William
  187. Roy
  188. ---8<---8<---8<---8<---8<---8<---
  189. */
  190.    
  191.     return 0;
  192. }
Advertisement
Add Comment
Please, Sign In to add comment