Advertisement
yepp

zh emberek

Jan 3rd, 2014
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4. #include <sstream>
  5. #include <string>
  6.  
  7. class Ember {
  8. public:
  9.     int eletkor;
  10.     int fizetes;
  11.     Ember(int e, int f) {
  12.         this->eletkor = e;
  13.         this->fizetes = f;
  14.     }
  15. };
  16.  
  17. std::vector<Ember> emberek;
  18. std::vector<Ember> beolvas(std::string filenev);
  19. int feladat1(std::vector<Ember> v);
  20. int feladat2(std::vector<Ember> v);
  21. int feladat3(std::vector<Ember> v);
  22. std::vector<int> feladat4(std::vector<Ember> v);
  23. std::vector<int> f4;
  24.  
  25. int main() {
  26.     emberek = beolvas("be1.txt");
  27.     //std::cout << "Bolvasva..." << std::endl;
  28.     std::cout << "" << feladat1(emberek) << std::endl;
  29.     std::cout << "" << feladat2(emberek) << std::endl;
  30.     std::cout << "" << feladat3(emberek) << std::endl;
  31.     f4 = feladat4(emberek);
  32.     std::cout << f4.size();
  33.     for (int i = 0; i < f4.size(); ++i) {
  34.         std::cout << " " << (f4.at(i)+1);
  35.     }
  36.     std::cout << std::endl;
  37.     return 0;
  38. }
  39.  
  40. std::vector<Ember> beolvas(std::string filenev) {
  41.     std::ifstream s(filenev.c_str());
  42.     std::string line;
  43.     std::getline(std::cin, line, '\n');
  44.     std::vector<Ember> res;
  45.     while (std::getline(std::cin, line)) {
  46.         std::istringstream iss(line);
  47.         int e,f;
  48.         iss >> e >> f;
  49.         res.push_back(Ember(e,f));
  50.     }
  51.     return res;
  52. }
  53.  
  54. int feladat1(std::vector<Ember> v) {
  55.     int i = 1;
  56.     int r = 0;
  57.     Ember a = v.at(0);
  58.     while (i < v.size()) {
  59.         if (v.at(i).eletkor > v.at(r).eletkor) {
  60.             r = i;
  61.         }
  62.         i++;
  63.     }
  64.     return r+1;
  65. }
  66.  
  67. int feladat2(std::vector<Ember> v) {
  68.     int sum = 0;
  69.     for (int i = 0; i < v.size() ; i++) {
  70.         if (v.at(i).eletkor > 40 && v.at(i).fizetes < 200000) {
  71.             sum++;
  72.         }
  73.     }
  74.     return sum;
  75. }
  76.  
  77. int feladat3(std::vector<Ember> v) {
  78.     bool e[150];
  79.     for (int i = 0; i < 150; i++) {
  80.         e[i] = false;
  81.     }
  82.     int sum = 0;
  83.     for (int i = 0; i < v.size(); i++) {
  84.         if (e[v.at(i).eletkor] == false) {
  85.             e[v.at(i).eletkor] = true;
  86.             sum++;
  87.         }
  88.     }
  89.     return sum;
  90. }
  91.  
  92. std::vector<int> feladat4(std::vector<Ember> v) {
  93.     std::vector<int> res;
  94.     for (int i = 0; i < v.size(); i++) {
  95.         if (v.at(i).eletkor < 30) {
  96.             res.push_back(i);
  97.         }
  98.     }
  99.     return res;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement