CDVA1601 - Editorial




Author: Dev Kumar

Tester: Aditya Kumar

Editorialist: Shubham Kabra




We are given an array of integers of length N and we have to perform the arithmetic operations in given sequence.


Evaluating the given sequence we can conclude that the operators will be in the order {/,,+,-,,+,-,/,+,-,/,,-,/,,+} and then the sequence will repeat untill last operation will be done.


For solving the operations according to given in the problem we can use many method. But here using switch statement become quite efficient. After storing all the integers in an array, declare a (long long) integer variable ‘answer’ and assign the first element of array to it.

Now, if N is equal to 1 then simply answer is first element of array else using a for loop from i=1 to i=N-1, we can use modulo operator(by 16) to decide which operation to perform for that particular value of i. For example division will be performed when i\%16 = 1,8,11,14 and addition will be performed when i\%16 = 0,3,6,9 (evaluate by given sequence).

So, use switch statement for these values to perform the division operation as answer divide by next value in array and store it again into answer variable.

One important and crucial point should be kept in mind that there might be a case where the division will be performed on a negative value i.e. if dividend<0 and dividend is not properly divisible by its divisor then result will be one less than division.

For example -5/4 = -1 but actually it should be -2 (as improper division gives it floor value, in C/ C++/ Java).


Author’s solution will be uploaded soon.

Tester’s solution can be found here.

Editorialist’s solution can be found here