Advertisement
Guest User

oep4

a guest
May 21st, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.91 KB | None | 0 0
  1. /*
  2. 4. Feladat:  Ki, és melyik versenyen fogott keszeget? Soroljuk fel, a megfelelőket!
  3. */
  4.  
  5. #include <iostream>
  6. #include "summation.hpp"
  7. #include "seqinfileenumerator.hpp"
  8. #include "stringstreamenumerator.hpp"
  9. #include "linsearch.hpp"
  10. #include "maxsearch.hpp"
  11.  
  12. using namespace std;
  13.  
  14. struct Fish {
  15.     string type;
  16.     int weight;
  17.     friend istream& operator >> (istream& in, Fish& fish) {
  18.         in >> fish.type >> fish.weight;
  19.         return in;
  20.     }
  21. };
  22.  
  23. class Caught : public LinSearch<Fish, false> {
  24.     virtual bool cond(const Fish& e) const {
  25.         return e.type == "keszeg";
  26.     }
  27. };
  28.  
  29.  
  30. struct Competitor {
  31.     string name;
  32.     string competition;
  33.     bool caught;
  34.     friend istream& operator >> (istream& in, Competitor& competitor) {
  35.         string line;
  36.         getline(in, line);
  37.         stringstream str(line);
  38.         string temp;
  39.         str >> competitor.name >> competitor.competition;
  40.  
  41.         StringStreamEnumerator<Fish> sse(str);
  42.         Caught caught;
  43.         caught.addEnumerator(&sse);
  44.         caught.run();
  45.         if (caught.found()) {
  46.             competitor.caught = true;
  47.         }
  48.         else {
  49.             competitor.caught = false;
  50.         }
  51.         //cout << competitor.name << " " << competitor.caught << endl;
  52.  
  53.         return in;
  54.  
  55.     }
  56. };
  57.  
  58.  
  59. class Draw : public Summation<Competitor,string> {
  60.     virtual string func(const Competitor& e) const {
  61.         return e.name + " " + e.competition + '\n';
  62.     }
  63.     virtual string neutral() const {
  64.         return "";
  65.     }
  66.     virtual string add( const string& a, const string& b) const {
  67.         return a + b;
  68.     }
  69.     virtual bool  cond(const Competitor& e) const {
  70.         return e.caught == true;
  71.     }
  72.  
  73. };
  74.  
  75. int main(){
  76.  
  77.     SeqInFileEnumerator<Competitor> sife("input.txt");
  78.     Draw draw;
  79.     draw.addEnumerator(&sife);
  80.     draw.run();
  81.     cout << draw.result();
  82.  
  83.  
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement