# | Problem | Pass Rate (passed user / total user) |
---|---|---|
13090 | Vector |
|
13091 | Student ID Map |
|
Description
Implement below six functions related to vector<int>.
void InsertBack(vector<int> &v, int num) – insert the number n into v from back.
For example:
insert 1 // vec = {1}
insert 2 // vec = {1, 2}
void Erase(vector<int> &v, int num) – delete the first number num found in v.
note: if there is no number num in v, print string “Can't find element: num” with a return value at the end.
For example:
insert 1 // vec = {1}
insert 2 // vec = {1, 2}
insert 1 // vec = {1, 2, 1}
erase 1 // vec = {2, 1}
erase 3 // there is no 3 in vec
Can’t find element: 3
void Reverse(vector<int> &v) – reverse all the elements in v.
For example:
insert 1 // vec = {1}
insert 2 // vec = {1, 2}
reverse // vec = {2, 1}
void Sort(vector<int> &v) – sort all the elements in v in ascending order.
note: you may use std::sort
For example:
insert 1 // vec = {1}
insert 3 // vec = {1, 3}
insert 2 // vec = {1, 3, 2}
sort // vec = {1, 2, 3}
void Print(vector<int> &v) – print out all the elements in v in index order. Each two elements (numbers) are separate by a space ‘ ‘.
note: if there is no elements in v, print string “None” with a return value at the end.
For example:
print // at first, vec is empty = {}
None
insert 1 // vec = {1}
insert 3 // vec = {1, 3}
insert 2 // vec = {1, 3, 2}
print // print out in index order
1 3 2
void Clear(vector<int> &v) – clear all the elements in v.
For example:
insert 1 // vec = {1}
insert 3 // vec = {1, 3}
insert 2 // vec = {1, 3, 2}
clear // vec is empty = {}
Input
There are six kinds of input command.
insert num – Call InsertBack(<vector reference>, num).
erase num – Call Erase(<vector reference>, num).
reverse – Call Reverse(<vector reference>).
sort – Call Sort(<vector reference>).
print – Call Print(<vector reference>).
clear – Call Clear(<vector reference>).
Output
Output followed by above rules.
Sample Input Download
Sample Output Download
Partial Judge Code
13090.cppPartial Judge Header
13090.hTags
Discuss
Description
Implement below four functions related to map<string, string>students_list. The student_lists map is used to store student id and student’s name. Use student's name as the map’s key, and student id as the map’s value.
For example:
students_list[“John”] = “s109004502”
note: the first englisg letter of student id reprsents as the student’s grade. Therefore, if the student moves on to the next level, the englisg letter should go down in alphabetical order.
For example:
s109004502 => t109004502
z109004502 => a109004502
void New(map<string, string> &mp, string name, string id) – add the student’s information <name, id> into students_list.
note: if the student’s information is already existed, then update the student’s information.
For example:
new Taka x351010105 // students_list = {<Taka, x351010105>}
new Masato m11111111 // students_list = {<Taka, x351010105>, <Masato, m11111111>}
new Masato c199612121 // students_list = {<Taka, x351010105>, <Masato, c199612121>}
void Delete(map<string, string> &mp, string name) – delete the student’s information <name, id> inside students_list.
note: if there is no the student’s information, print string “No such student named: name” with a return value at the end.
For example:
new Taka x351010105 // students_list = {<Taka, x351010105>}
delete Masato // there is no Masato’s information
No such student named: Masato
delete Taka// students_list is empty, students_list = {}
void Show(map<string, string> &mp, string name) – print out the student’s information <name, id> inside students_list. The student’s name and the student’s id should be separate by a space ‘ ‘.
note: if there is no the student’s information, print string “No such student named: name” with a return value at the end.
For example:
new Taka x351010105 // students_list = {<Taka, x351010105>}
show Masato // there is no Masato’s information
No such student named: Masato
show Taka
Taka x351010105
void MoveOnNextLevel(map<string, string> &mp, string name) – update the student’s information <name, id> inside students_list.
note: if there is no the student’s information, print string “No such student named: name” with a return value at the end.
For example:
new Taka x351010105 // students_list = {<Taka, x351010105>}
moveon Masato // there is no Masato’s information
No such student named: Masato
moveon Taka // students_list = {<Taka, y351010105>}
moveon Taka // students_list = {<Taka, z351010105>}
moveon Taka // students_list = {<Taka, a351010105>}
Input
There are four kinds of input command.
new name id – Call New(<map reference>, name, id).
delete name – Call Delete(<map reference>, name).
show name – Call Show(<map reference>, name).
moveon name– Call MoveOnNextLevel(<mapreference>, name).
Output
Output followed by above rules.