Advertisement
Ermolaxe

Algorithm+pair #2(struct)

Jul 2nd, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <string>
  6. int i=1;
  7. using namespace std;
  8.  
  9.  
  10. ifstream fin("input.txt");
  11. ofstream fout("output.txt");
  12.  
  13. struct Student
  14. {
  15.         string name;
  16.         int bookNumber;
  17.         string fac;
  18.         int number;
  19.         int estimates[5];
  20. public:
  21.         void Read()
  22.         {
  23.                 fin >> name >> bookNumber >> fac >> number;
  24.                 for (int i=0;i<5;i++)
  25.                 {
  26.                         fin >> estimates[i];
  27.                 }
  28.         }
  29.  
  30.         void Print()
  31.         {
  32.                 fout << name << " " << bookNumber << " " << fac << " " << number << " ";
  33.                 for (int i=0;i<5;i++)
  34.                 {
  35.                         fout << estimates[i] << " ";
  36.                 }
  37.                 fout << endl;
  38.         }
  39. };
  40.  
  41. bool cmp(Student stud)
  42. {
  43.         if (stud.estimates[0]==2 || stud.estimates[1]==2 || stud.estimates[2]==2 || stud.estimates[3]==2 || stud.estimates[4]==2) return true;
  44.         else return false;
  45. }
  46.  
  47. void func(Student stud)
  48. {
  49.     if (stud.estimates[0]==2 || stud.estimates[1]==2 || stud.estimates[2]==2 || stud.estimates[3]==2 || stud.estimates[4]==2)
  50.         {
  51.             fout << i <<" ";
  52.         }
  53.     i++;
  54. }
  55.  
  56. int main()
  57. {
  58.         int n,count=0;
  59.         fin >> n;
  60.  
  61.         vector <Student> stud(n);
  62.  
  63.         for (int i=0;i<n;i++)
  64.         {
  65.                 stud[i].Read();
  66.         }
  67.  
  68.         count=count_if(stud.begin(), stud.end(), cmp);
  69.      
  70.         fout << count << endl;
  71.            
  72.         for_each(stud.begin(), stud.end(), func);
  73.  
  74.         return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement