# | Problem | Pass Rate (passed user / total user) |
---|---|---|
13073 | Vector & Sorting |
|
13074 | Map |
|
Description
Input a sequence of numbers. Please insert them into a vector, and sort them in ascenind order(ASC) and in descending order(DESC) by bubble sort and sort() in stl repectively.
Complete below three functions and two existed class BubbleSort, STLSort.
void InputVector(vector<int> &vec, int n) – stdin n numbers and insert them into vec from back.
void CopyVector(vector<int> &vec, vector<int> &other) – copy all elements in vec and replace elements in other with them.
note: vec and other would own same elements after this function.
For example:
vec = {1, 3, 5, 7} other = {2, 4, 6, 8, 10}
after CopyVector(vec, other)
vec = {1, 3, 5, 7} other = {1, 3, 5, 7}
void PrintVector(vector<int> &vec) – print out all elements in vec in order.
note: need print return value at the end.
BubbleSort
Private Methods:
- void swap(int *ptr1, int *ptr2) – Swap the value pointed by ptr1 and the value pointed by ptr2
Public Methods:
- void sort(vector<int> &vec, bool ascending = true) – Sort elements in vec. Sort in ascending order if ascending is true; otherwise, sort in descending order. (no need implement)
STLSort
Public Methods:
- void sort(vector<int> &vec, bool ascending = true) – Sort elements in vec. Sort in ascending order if ascending is true; otherwise, sort in descending order.
note: use STL sort, it’s super easy.
function.cpp: download
Input
n
N1 N2 N3 N4 … Nn
n represents the total number of numbers (N1, N2, N3 …) appear in the next line.
note: 20 >= n > 0. Also, numbers appear in next line are bounded in normal c++ int data type.
Output
No need to handle output. Its shown in main.cpp.
Sample Input Download
Sample Output Download
Partial Judge Code
13073.cppPartial Judge Header
13073.hTags
Discuss
Description
You are appointed as the assistant to a teacher in a school and that teacher is correcting the answer sheets of the students. Each student can have multiple answer sheets. So the teacher has Q queries in below format:
1 student_name marks: Add the marks to the student whose name is student_name .
2 student_name: Erase the marks of the students whose name is student_name.
3 student_name: Print the marks of the students whose name is student_name. (If student_name didn't get any marks print 0.)
Copy from: https://www.hackerrank.com/challenges/cpp-maps/problem
Let me be lazy once. BTW, Hackerrank (https://www.hackerrank.com/) is a great website that helps you learning code. Go check it out.
Input
The first line of the input contains Q where Q is the total number of queries. The next Q lines contain 1 query each. The first integer, type, of each query is the type of the query.
If type is 1, it consists of one string and an integer, student_name and marks where student_name is the name of the student and marks is the marks of the student.
If type is 2 or 3, it consists of a single string student_name where student_name is the name of the student.
Output
For queries of type 3 print the marks of the given student.