## A Long Problem

View as PDF

Points: 1 (partial)
Time limit: 5.0s
Memory limit: 1G

Author:
Problem type
Allowed languages
C++

You will be given functions to implement; then, your functions will be graded in random order. If any of your functions do not receive an AC verdict, you will be awarded the prefix of correct functions.

Note: If you do not implement every function and return an answer, you will receive a CE (Compilation Error) or RTE (Runtime Exception) verdict.

#### Function 1

int divide(int a, int b)

• : the dividend.
• : the divisor.
• This procedure should return the quotient of and (i.e., the integer result of ).
• This procedure will be called up to times.

divide(5, 2) should return 2.

#### Function 2

int count_occurrences(string s, string pattern)

• : the string to search for the pattern.
• : the pattern to find in the string.
• This procedure should return the number of occurrences of in .
• This procedure will be called up to times.
• and will only contain lowercase letters.
• Note that denotes the length of the string .

count_occurrences("babab", "bab") should return 2.

#### Function 3

vector<int> sort_array(vector<int> arr)

• : the vector of integers to sort.
• This procedure should return in ascending order (i.e., it should be strictly non-decreasing).
• This procedure will be called up to times.
• Note that denotes the length of vector , and that denotes every integer in the vector .

sort_array({5, 3, 6000, 20}) should return {3, 5, 20, 6000}.

#### Function 4

int max_size_k(vector<int> arr, int k)

• : the vector of integers to find the maximum subarray.
• : the size of the maximum size subarray to find.
• This procedure should return the maximum sum of a subarray of size in .
• This procedure will be called up to times.
• Note that denotes the length of vector , and that denotes every integer in the vector .

max_size_k({5, 6, 100, 20, 5}, 2) should return 120.

#### Function 5

char find_upper(char ch)

• : the lowercase letter to be converted to uppercase.
• This procedure should return the uppercase version of .
• This procedure will be called up to times.
• will be a lowercase letter.

find_upper('c') should return 'C'.

#### Function 6

bool is_prime(int n)

• : the number to check primality.
• This procedure should return true if is prime and false if is not prime.
• This procedure will be called up to times.

is_prime(107) should return true.

#### Function 7

int distinct_integers(vector<int> arr)

• : the vector to count the number of distinct integers.
• This procedure should return the number of distinct integers in .
• This procedure will be called up to times.
• Note that denotes the length of vector , and that denotes every integer in the vector .

distinct_integers({5, 100, 3, 20, 20, 5, 1}) should return 5.

#### Function 8

bool is_inside(int x, int y, int rx, int ry, int w, int h)

• : the x-coordinate of the bottom-left of the rectangle.
• : the y-coordinate of the bottom-left of the rectangle.
• : the x-coordinate of the rock.
• : the y-coordinate of the rock.
• : the rectangle's width (the length that it extends horizontally in the positive x-direction).
• : the rectangle's height (the length that it extends vertically in the positive y-direction).
• This procedure should return true if the rock is contained (or on the side) of the rectangle and false otherwise.
• This procedure will be called up to times.

is_inside(1, 1, 5, 5, 4, 4) should return true.

#### Function 9

bool is_even(int n)

• : the number to check evenness.
• This procedure should return true if is an even number and false otherwise.
• This procedure will be called up to times.

is_even(5) should return false.

#### Function 10

bool is_bit_on(int bit, int num)

• : the number of the bit to check if it's on.
• : the number to check for the bit.
• This procedure should return true if the rightmost zero-indexed bit is toggled on in the binary representation of and false otherwise.
• This procedure will be called up to times.

is_bit_on(2, 4) should return true.

#### Function 11

int create_max(vector<int> dig)

• : the vector of integers to reorder to find the maximum possible number.
• This procedure should return the maximum number created by reordering the digits in .
• This procedure will be called up to times.
• Note that denotes the length of vector , and that denotes every integer in the vector .

create_max({0, 0, 9, 3, 9}) should return 99300.

#### Function 12

int factorial(int n, int m)

• : the number to calculate its factorial.
• : the number to mod the answer by.
• This procedure should return mod ( is the product of all integers from to , and mod returns the remainder after dividing by ).
• This procedure will be called up to times.

factorial(50, 100007) should return 34694.

#### Function 13

bool should_feed(int h, int m, int th)

• : the hunger level of the dog.
• : the multiplier of the hunger level to get the hunger score.
• : the threshold where you will feed the dog if its hunger score is greater than or equal to this.
• This procedure should return true if the hunger score (calculated by multiplying by ) is greater than or equal to and false otherwise.
• This procedure will be called up to times.

should_feed(1, 1, 1) should return true.

#### Function 14

pair<int, int> lowest_terms(int num, int denom)

• : the numerator of the fraction.
• : the denominator of the fraction.
• This procedure should return the fraction in lowest terms (i.e., their greatest common divisor is ) with the numerator as the first element and denominator as the second element.
• This procedure will be called up to times.

lowest_terms(5, 15) should return {1, 3}.

#### Function 15

int find_sum(int n)

• : the number to sum all numbers up to.
• This procedure should return the sum of natural numbers up to and including .
• This procedure will be called up to times.

find_sum(5) should return 15.

#### Function 16

string find_type(int type)

• : the number corresponding to the different strings in the problem.
• This procedure should return max, do if is 1, dhruv, fold if is 2, abayomi, open if is 3, snjezana, write if is 4, yuxuan, close if is 5, mohamed, move if is 6, scarlet, crush if is 7, anastasia, tear if is 8, aksana, press if is 9, alejandro, cut if is 10.
• This procedure will be called up to times.

find_type(6) should return "mohamed, move".

#### Function 17

string largest_lex(vector<string> arr)

• : the vector of strings to find the maximum lexicographical string.
• This procedure should return the lexicographically largest string in (for two strings that differ at a specific character, one string is lexicographically larger if that letter is further in the alphabet than the other letter).
• If two strings have different lengths but identical prefixes, prefer the longer string.
• This procedure will be called up to times.
• Each string will only contain lowercase letters.
• Note that denotes the length of vector , and that denotes every string in the vector .

largest_lex({"abc", "bca", "dcd", "cba"}) should return "dcd".

#### Function 18

vector<int> add_colours(vector<int> c1, vector<int> c2)

• : the red, green, and blue integer values of colour 1.
• : the red, green, and blue integer values of colour 2.
• This procedure should return the sum of each red, green, and blue value in colours 1 and 2 as a vector with red as the first value, green as the second, and blue as the third.
• This procedure will be called up to times.
• Note that a colour can only have a maximum value of for a red, green, or blue value after summing.
• Note that denotes the length of vector , and that denotes every integer in the vector .

add_colours({255, 50, 125}, {255, 0, 100}) should return {255, 50, 225}.

#### Function 19

string remove_occurrences(string s, string pattern)

• : the string to remove all occurrences of from.
• : the pattern to remove from .
• This procedure should return after removing all occurrences of from it.
• This procedure will be called up to times.
• Note that earlier matches take precedence.
• and will only contain lowercase letters.
• Note that denotes the length of the string .

remove_occurrences("abcabcab", "abcab") should return "cab".

#### Function 20

bool AC()

• This procedure should return true.
• This procedure will be called up to times.

AC() should return true.