Practice
Author: Ritvik
Tester: Ritvik
Editorialist: Ritvik
DIFFICULTY:
EASY
PREREQUISITES:
Math, Array
PROBLEM:
To add 1 or 2 to every digit of a 6 digits array from a set of digits S={1, 2, 3, 4, 5, 6, 7} of numbers based on their even or odd index respectively.
The correct array of digits can be from 1-9.
EXPLANATION:
As per the prompt, the given array is incorrect and we have to add 1 if the index value of the digit is even and 2 in case of odd.
For eg. 1 7 4 6 2 5 is incorrect and we have to add 1 and 2 based on even and odd indexes. Hence, the correct array of numbers becomes 2 9 5 8 3 7.
SOLUTION:
Setter's Solution
#include <iostream>
using namespace std;
int main() {
int t;
cin >> t;
int nums[6];
for (int i = 0; i < t; i++) {
for (int j = 0; j < 6; j++) {
cin >> nums[j];
if (nums[j] > 7)
cout << "error" << endl;
else {
if (j % 2 == 0)
cout << nums[j] + 1 << " ";
else
cout << nums[j] + 2 << " ";
}
}
cout << endl;
}
return 0;
}