Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- struct student{
- string id,name,surname,patr;
- int group_number;
- double av_score;
- };
- bool comp(student &a, student &b){
- return a.id < b.id;
- }
- vector<student> find_group(vector<student> &a, int &need_group){
- vector<student> b;
- for(int i = 0; i < a.size(); i++)
- if(a[i].group_number == need_group)
- b.push_back(a[i]);
- return b;
- }
- student find_id(vector<student> &a, string &need_id){
- int l = 0, r = a.size();
- while(l <= r){
- int m = (l+r)/2;
- if(a[m].id > need_id)
- r = m - 1;
- else if(a[m].id < need_id)
- l = m + 1;
- else if(a[m].id == need_id)
- return a[m];
- }
- }
- signed main(){
- int n; // amount of students
- cin >> n;
- vector<student> a(n);
- for(int i = 0; i < n; i++)
- cin >> a[i].id >> a[i].name >> a[i].surname >> a[i].patr >> a[i].group_number >> a[i].av_score;
- int x; // need group
- cin >> x;
- vector<student> b = find_group(a,x); // vector of students with needed group number (task 3)
- sort(a.begin(),a.end(),comp);
- string s; // need id
- cin >> s;
- student c = find_id(a,s); // student with needed id (task 4)
- }
Advertisement
Add Comment
Please, Sign In to add comment