ZeroJudge K467: Class

Wenwen's school hopes to allow students to develop their individual talents, so they plan to divide students into language and literature classes and mathematics and science classes. To distinguish students' abilities, the school has prepared language-related tests and mathematics-related tests.

If a student's language score is higher than their mathematics score, they will be assigned to the language and literature class; otherwise, they will be assigned to the mathematics and science class.

Through this method of class allocation, the school aims to provide students with a better learning experience and outcomes. Students can focus more on their strengths and receive more challenges in those areas, ultimately leading to better learning experiences and achievements.

For example, let's say Wenwen's school has five students, numbered from 1, with the following language scores: 77, 74, 89, 98, and 82, and the following mathematics scores: 98, 77, 76, 74, and 93. According to the school's method of class allocation, students whose language scores are higher than their mathematics scores will be assigned to the language and literature class. Therefore, students number 3 and 4 will be assigned to the language and literature class. Conversely, students number 1, 2, and 5 will be assigned to the mathematics and science classes.
Please design a program to help students get assigned to classes smoothly.

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
The first line of input consists of an integer N (1 ≤ N ≤ 1000), indicating the number of students. The second line contains N integers L_i (1 ≤ L_i ≤ 100, 1 ≤ i ≤ N), representing the language scores of all students. The third line contains N integers M_i (1 ≤ M_i ≤ 100, 1 ≤ i ≤ N), representing the mathematics scores of all students. It is guaranteed that the scores of each student in the two subjects are different.The output consists of two lists: the first list represents the student numbers in the language and literature class, and the second list represents the student numbers in the mathematics and science class. The student numbers should be sorted in ascending order, and separated by a single space. If a class has no students, output -1 for that class.
3
80 70 99
91 90 93
3
1 2
5
77 74 89 98 82
98 77 76 74 93
3 4
1 2 5
6
71 61 61 96 60 62
72 85 93 99 74 76
-1
1 2 3 4 5 6
ZeroJudge K467 Sample Test Case

Thought Process

When collecting language scores, store the scores in an array and declare two arrays, language and math, to store the student numbers for the language and mathematics classes, respectively.

收數學成積的時候直接和語文成績陣列中的內容做比大小,並且將目前的座號存放到對應的陣列中。

Before outputting the array data, check if the length of the array is 0. If it is 0, output -1.

Sample Code-ZeroJudge K467: Class

#include <iostream>
#include <vector>
using namespace std;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int>score, language, math;
    for (int i = 0; i<N; i++)
    {
        int tmp;
        cin >> tmp;
        score.push_back(tmp);
    }
    for (int i = 0; i<N; i++)
    {
        int tmp;
        cin >> tmp;
        if (tmp > score[i]) math.push_back(i+1);
        else language.push_back(i+1);
    }
    if (language.size() == 0) cout << -1;
    for (int i = 0; i<language.size(); i++)
    {
        cout << language[i] << " ";
    }
    cout << "\n";
    if (math.size() == 0) cout << -1;
    for (int i = 0; i<math.size(); i++)
    {
        cout << math[i] << " ";
    }
    cout << "\n";
}

//ZeroJudge K467
//Dr. SeanXD

Comments