Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- struct Student {
- string name;
- string surName;
- double mark;
- };
- int main() {
- int n;
- cin >> n;
- Student arr[1000];
- for (int i = 0; i < n; i++) {
- cin >> arr[i].name;
- cin >> arr[i].surName;
- cin >> arr[i].mark;
- }
- string command;
- cin >> command;
- if (n == 0) {
- cout << "-1";
- }
- if (command == "max") {
- int first = 0;
- for (int i = 0; i < n; i++) {
- if (arr[i].mark > arr[first].mark) {
- first = i;
- }
- }
- cout << arr[first].name << " " << arr[first].surName;
- }
- else if (command == "avg") {
- bool a = false;
- double sum = 0.0;
- for (int i = 0; i < n; i++) {
- sum += arr[i].mark;
- }
- int mid = sum / n;
- for (int i = 0; i < n; i++) {
- if (arr[i].mark > mid) {
- a = true;
- cout << arr[i].name << " " << arr[i].surName << endl;
- }
- }
- if (a == false) {
- cout << "-1";
- }
- }
- else {
- bool a = false;
- string name;
- cin >> name;
- for (int i = 0; i < n; i++) {
- if (arr[i].name == name) {
- a = true;
- cout << arr[i].name << " " << arr[i].surName << endl;
- }
- }
- if (a == false) {
- cout << "-1";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement