ZeroJudge E925: Verifying Student ID

University student IDs consist of nine digits.

The first digit represents the student's status (for example, "B" for undergraduate students). The second and third digits represent the last two digits of the admission year. The fourth, fifth, sixth, and seventh digits represent the codes for college, department, and group. The eighth and ninth digits represent the student's serial number.

This question assumes that the university always has the following colleges, departments, and groups (please refer to the sample input for all college, department, and group codes):
-1000 College of Liberal Arts
-2000 College of Science
-3000 College of Social Sciences
-And so on...

This question assumes that each group can admit 100 students (the eighth and ninth digits range from "00" to "99").


Now, from a pile of university student IDs, ten IDs are randomly selected. Write a program to verify if these ten IDs are valid and calculate the error rate.
For example, for the following ten student IDs:

B00100000 R00100000 // Does not match the code for undergraduate students BA0100000 // Does not match the code for admission year B00101300 // Does not match the code for department and group B001000A0 // Does not match the code for serial number B09902005 B06A01233 B12701256 B80310020 B98901030

The result is Y, N, N, N, N, Y, Y, Y, Y, Y. The error rate is 0.4.

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
The first line of input consists of a positive integer N (1≤N≤76),
representing that there are N departments or groups.
Next, there are N lines of text,
Each line consists of four characters representing the codes for the colleges, departments, and groups.
Finally, there are 10 lines of text.
Each line consists of nine characters representing the student IDs to be validated.
If the validation is successful, output "Y"; if it fails, output "N." Finally, output the failure rate of the validation.
76
0000
1000
1010
1011
1020
1030
1040
1050
1060
1070
1090
2000
2010
2020
2030
2040
2070
2080
2090
3000
3021
3022
3023
3030
3050
3100
4000
4010
4020
4030
4031
4040
4060
4080
4081
4090
4120
5000
5010
5020
5040
5050
5070
5080
6000
6010
6020
6030
6050
6060
6070
6080
6090
6100
6110
6120
6130
7000
7011
7012
7020
7030
7040
7050
8000
8010
9000
9010
9020
A000
A011
A012
A013
B000
B010
B020
B00100000
R00100000
BA0100000
B00101300
B001000A0
B09902005
B06A01233
B12701256
B80310020
B98901030
Y
N
N
N
N
Y
Y
Y
Y
Y
0.4
ZeroJudge E925 範例測資

Thought Process

You can use a map to check if the middle four characters have appeared before. When outputting the failure rate, if there are no validation failures, output "0" instead of "0.0". If all fail, output "1" instead of "0.10" or "1.0".

Sample Code-ZeroJudge E925: Verifying Student ID

#include <iostream>
#include <map>
#include <cctype>
using namespace std;

int main() {
    int N;
    cin >> N;
    map<string, int>MAP;
    for (int i = 0; i<N; i++)
    {
        string str;
        cin >> str;
        MAP[str]++;
    }
    int wrong = 0;
    for (int i = 0; i<10; i++)
    {
        string str;
        cin >> str;
        if (str[0] != 'B')
        {
            wrong++;
            cout << "N\n";
            continue;
        }
        if (!isdigit(str[1]) || !isdigit(str[2]))
        {
            wrong++;
            cout << "N\n";
            continue;
        }
        string tmp = "";
        for (int j = 3; j<=6; j++)
        {
            tmp += str[j];
        }
        if (MAP[tmp] == 0)
        {
            wrong++;
            cout << "N\n";
            continue;
        }
        if (!isdigit(str[7]) || !isdigit(str[8]))
        {
            wrong++;
            cout << "N\n";
            continue;
        }
        cout << "Y\n";
    }
    if (wrong == 0) cout << 0 << "\n";
    else if (wrong == 10) cout << 1 << "\n";
    else cout << "0." << wrong << "\n";
}

//ZeroJudge E925
//Dr. SeanXD

Comments