2222 - IP_2020_YOU_HW10 Scoreboard

Time

2020/12/22 12:00:00 2020/12/29 12:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
13073 Vector & Sorting
13074 Map

13073 - Vector & Sorting   

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

#include "function.h"
#include <bits/stdc++.h>
 
using namespace std;
 
/* Vector */
void InputVector(vector<int&vecint n)
{
    // Todo
}
 
void CopyVector(vector<int&vecvector<int&other)
{
    // Todo
}
 
void PrintVector(vector<int&vec)
{
    // Todo
    // Note: Remember to print '\n' at the end
}
 
/* Bubble Sort */
void BubbleSort::swap(int *ptr1int *ptr2)
{
    // Todo
}
 
void BubbleSort::sort(vector<int&vecbool ascending)
{
    if (vec.size() < 2)
        return;
 
    for (int i = vec.size(); i > 1i--)
    {
        for (int j = 0j < i - 1j++)
        {
            if (ascending)
            {
                if (vec[j] > vec[j + 1])
                    swap(&vec[j], &vec[j + 1]);
            }
            else
            {
                if (vec[j] < vec[j + 1])
                    swap(&vec[j], &vec[j + 1]);
            }
        }
    }
}
 
/* STL Sort */
void STLSort::sort(vector<int&vecbool ascending)
{
    if (ascending)
    {
        // Todo
    }
    else
    {
        // Todo
    }
}

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.cpp

Partial Judge Header

13073.h

Tags




Discuss




13074 - Map   

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.

Sample Input  Download

Sample Output  Download

Tags




Discuss