Guest User

Untitled

a guest
Sep 17th, 2020
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. struct student{
  7.     string id,name,surname,patr;
  8.     int group_number;
  9.     double av_score;
  10. };
  11.  
  12. bool comp(student &a, student &b){
  13.     return a.id < b.id;
  14. }
  15.  
  16. vector<student> find_group(vector<student> &a, int &need_group){
  17.     vector<student> b;
  18.     for(int i = 0; i < a.size(); i++)
  19.         if(a[i].group_number == need_group)
  20.             b.push_back(a[i]);
  21.     return b;
  22. }
  23.  
  24. student find_id(vector<student> &a, string &need_id){
  25.     int l = 0, r = a.size();
  26.     while(l <= r){
  27.         int m = (l+r)/2;
  28.         if(a[m].id > need_id)
  29.             r = m - 1;
  30.         else if(a[m].id < need_id)
  31.             l = m + 1;
  32.         else if(a[m].id == need_id)
  33.             return a[m];
  34.     }
  35. }
  36.  
  37. signed main(){
  38.     int n; // amount of students
  39.     cin >> n;
  40.     vector<student> a(n);
  41.     for(int i = 0; i < n; i++)
  42.         cin >> a[i].id >> a[i].name >> a[i].surname >> a[i].patr >> a[i].group_number >> a[i].av_score;
  43.     int x; // need group
  44.     cin >> x;
  45.     vector<student> b = find_group(a,x); // vector of students with needed group number (task 3)
  46.     sort(a.begin(),a.end(),comp);
  47.     string s; // need id
  48.     cin >> s;
  49.     student c = find_id(a,s); // student with needed id (task 4)
  50. }
Advertisement
Add Comment
Please, Sign In to add comment