Задача 7. Sum Arrays
Здравейте, чудих се къде греша? В нулевите тестове всичко минава както си трябва, но на останалите не става. Дава ми 50/100.
Ето го и кода ми: https://pastebin.com/tf88pttj
Write a program that reads two arrays of integers and sums them. When the arrays are not of the same size, duplicate the smaller array a few times.
Examples
Input |
Output |
Comments |
1 2 3 4 2 3 4 5 |
3 5 7 9
|
1 2 3 4 + 2 3 4 5 = 3 5 7 9 |
1 2 3 4 5 2 3 |
3 5 5 7 7
|
1 2 3 4 5 + 2 3 2 3 2 = 3 5 5 7 7 |
5 4 3 2 3 1 4 |
7 7 4 9
|
5 4 3 5 + 2 3 1 4 + 7 7 4 9 |
Hints
- Assume the first array arr1 has len1 elements and the second arr2 has len2 elements.
- The result array will have max(len1, len2) elements.
- We sum array elements one by one (from the first to the last). To enable rotating (take the first element as next after the last), we use the position % length indexing: arr1[i % len1] and arr2[i % len2].