Structure - who won the most scholarships?

Posted by rubio on Tue, 25 Jan 2022 00:07:26 +0100

Don't say anything else, give me the scholarship first

analysis

Understanding: we can understand it as a template, but at the same time, we can regard it as a user-defined type, just like int, short and char. The class we learned later is actually very similar in structure to struct.

Struct is a keyword, and the structure name after struct is artificially set, and the structure name can be regarded as a template with attributes.

                                                                                                            --------Promer_Wang

//Create student structure
struct Student{
//Attribute name
	char name[20];		//First name (characters)
	int weight;			//weight
	int age;			//Age
}; 

After we create this structure, we can use the structure, that is, the template, that is, the Student above, and we can understand the Student as a keyword similar to int, short and char. We can use Student to define variables, and variables defined with Student also have memory.
However, what we need to say here is that Student is a template, which has its own properties. If an object is created with such a template with properties, the created object will have the same properties.
                                                                                                            --------Promer_Wang

//Create student structure
struct Student{
//Attribute name
	char name[20];		//First name (characters)
	int weight;			//weight
	int age;			//Age
}Stu[10005]; //Structure variable = = > write: struct student stu in the main function (struct can be omitted) 

Structure Sorting ------ sort() + CMP

Sort format: sort (first, end, cmp);

First: the starting subscript of the number to be sorted

End: the subscript of the next number of the last number to be sorted

cmp: indicates the specified sorting method; optional, i.e. ascending by default

 Tips :

bool cmp(Student x, Student y) { // bool returns true or false, or int returns 0 / 1
    if(x.age == b.age) {
        if(x.high == y.high) {
            return x.weigh < y.weigh;
        }
        else {
            return x.high > y.high;
        }
    }
    else{
        return x.age < y.age;
    }
}

The above figure shows a more complex sorting method, which requires multiple judgment and screening

--->Sort by age from small to large. If the age is the same, sort by height from high to low. If the height is the same, sort by weight from small to large (the weight is not the same...)

Tips:   name    age  high  kg

in:    zhangsan  16  1.67  53 
         lisi    16  1.56  43
        wangba   16  1.67  65

out:    zhangsan---wangba---lisi

Who won the most scholarships?????

It must be me

Title Description

It is the practice of a school to grant scholarships after the final examination of each semester. There are five kinds of scholarships, with different conditions:

1) . academician scholarship, 8000 yuan per person, with a final average score of more than 80 (> 80) and one or more papers published in this semester;

2) The May 4th scholarship is 4000 yuan per person. Students with a final average score of more than 85 (> 85) and a class evaluation score of more than 80 (> 80) can be awarded;

3) . excellent performance award, 2000 yuan per person. Students with an average score of more than 90 (> 90) at the end of the term can obtain it;

4) The Western scholarship is 1000 yuan per person. Students from western provinces with an average score of more than 85 (> 85) at the end of the term can obtain it;

5) Class contribution award, 850 yuan per person, student cadres with class evaluation scores higher than 80 (> 80) can be awarded;

As long as they meet the conditions, they can win awards. There is no limit on the number of winners of each scholarship, and each student can also obtain multiple scholarships at the same time. For example, Yao Lin's final average score is 87 points, and his class evaluation score is 82 points. At the same time, he is also a student cadre, so he can get the May 4th scholarship and class contribution award at the same time. The total amount of bonus is 4850 yuan.

Now give the relevant data of some students. Please calculate which students get the highest total bonus (assuming that there are always students who can meet the conditions for obtaining scholarships).

Input format

The first line entered is an integer n (1 < = n < = 100), representing the total number of students. In the next n rows, each row is the data of a student. From left to right, it is the name, final average score, class evaluation score, whether it is a student cadre, whether it is a student in western provinces, and the number of papers published. The name is a string composed of upper and lower case English letters with a length of no more than 20 (excluding spaces); The final average score and class evaluation score are integers between 0 and 100 (including 0 and 100); Whether it is a student cadre and whether it is a student in western provinces are represented by one character respectively, Y means yes and N means no; The number of papers published is an integer from 0 to 10 (including 0 and 10). Every two adjacent data items are separated by a space.

Output format

The output consists of three lines. The first line is the name of the student who received the most bonus, and the second line is the total amount of bonus received by this student. If two or more students receive the most bonuses, output the name of the student who appears first in the input file. The third line is the total number of scholarships received by these N students.

Sample

sample input

4
YaoLin 87 82 Y N 0
ChenRuiyi 88 78 N Y 1
LiXin 92 88 N N 0
ZhangQin 83 87 Y N 1

sample output

ChenRuiyi
9000
28700

It requires a lot of judgment to distinguish the boundaries and the amount of scholarships awarded under different circumstances

Paste code

#include <iostream>
#include <cstring>
using namespace std;
struct student
{
    string name;
    int terminal; // Final average score
    int evaluation; // Class evaluation results
    char cadres; // Is it a student cadre
    char west; // Western provinces
    int papers; // Number of papers
    int money=0; // Scholarships obtained
} stu[100];
int main()
{
    int N, i, index, totalMoney;
    cin >> N;
    for (i=0; i<N; i++){
        cin >> stu[i].name >> stu[i].terminal >> stu[i].evaluation >> stu[i].cadres >> stu[i].west >> stu[i].papers;
        if (stu[i].terminal>80 && stu[i].papers>0) stu[i].money += 8000; // Academician scholarship
        if (stu[i].terminal>85 && stu[i].evaluation>80) stu[i].money += 4000; // May 4th scholarship
        if (stu[i].terminal>90) stu[i].money += 2000; // Outstanding achievement award
        if (stu[i].terminal>85 && stu[i].west=='Y') stu[i].money += 1000; // Western Scholarship
        if (stu[i].evaluation>80 && stu[i].cadres=='Y') stu[i].money += 850; // Class Contribution Award
        
    }
    index = 0;
    totalMoney = stu[0].money;
    for (i=1; i<N; i++){
        if (stu[i].money > stu[index].money)
            index = i;
        totalMoney += stu[i].money;
    }
    cout << stu[index].name << endl;
    cout << stu[index].money << endl;
    cout << totalMoney << endl;
    return 0;
}

Topics: C++ Algorithm