Eight problems for references and for passing vectors and strings. Read each statement's limits: several of them allow an empty array.
- Order Two: a
void order(long long &a, long long &b)that swaps the two when they are in the wrong order. Without the&, nothing reachesmain. - Sum an Array and Count in Range allow n = 0, and then the second line is
empty. A loop that runs 0 times handles it; the sum of nothing is 0. The sum of
2·10⁵ numbers of up to 10⁹ needs a
long long. - Array Stats asks for three answers about each of three arrays: one function
with a
const vector<long long> &and three reference parameters, called three times. - String Character Counts is the same idea for a string: one function fills in the vowels, consonants and digits.
- Even Sum Winner: a
readVectorfunction, called twice, and anevenSumthat skips the odd numbers. Negative even numbers count too. - Three Sorted Checks: each line starts with its length, which can be 0. An
isSorted(const vector<int> &a)compares each element with the next one. - Palindrome Check: when n = 0 the string is empty, and the empty string is a palindrome. Read the string only when n > 0.