Олимпиадный тренинг

Задача . 37450


Задача

Темы:
Refer to method match below:
/** @param v an array of int sorted in increasing order
* @param w an array of int sorted in increasing order
* @param N the number of elements in array v
* @param M the number of elements in array w
* @return true if there is an integer k that occurs
* in both arrays; otherwise returns false
* Precondition:
* v[0]..v[N-1] and w[0]..w[M-1] initialized with integers.
* v[0] < v[1] < .. < v[N-1] and w[0] < w[1] < .. < w[M-1].
*/

public static bool match(int[] v, int[] w, int N, int M)
{
    int vIndex = 0, wIndex = 0;
    while (vIndex < N && wIndex < M)
    {
        if (v[vIndex] == w[wIndex])
            return true;
        else if (v[vIndex] < w[wIndex])
            vIndex++;
        else
            wIndex++;
    }
    return false;
}

Assuming that the method has not been exited, which assertion is true at the end of every execution of the while loop?
(A) v[0]..v[vIndex-1] and w[0]..w[wIndex-1] contain no common value, vIndex ≤ N and wIndex ≤ M.
(B) v[0]..v[vIndex] and w[0]..w[wIndex] contain no common value, vIndex ≤ N and wIndex ≤ M.
(C) v[0]..v[vIndex-1] and w[0]..w[wIndex-1] contain no common value, vIndex ≤ N-1 and wIndex ≤ M-1.
(D) v[0]..v[vIndex] and w[0]..w[wIndex] contain no common value, vIndex ≤ N-1 and wIndex ≤ M-1.
(E) v[0]..v[N-1] and w[0]..w[M-1] contain no common value, vIndex ≤ N and wIndex ≤ M.

time 1000 ms
memory 32 Mb
Правила оформления программ и список ошибок при автоматической проверке задач

Статистика успешных решений по компиляторам
Комментарий учителя