Arrays > 04. Grab and Go
Здравейте,
Judge ми дава само 57/100. Не мога да си открия грешката...
Условие:
-
Grab and Go
Write a program, which receives an array of integers and an integer as input. Find the last occurrence of the integer in the given array and print the sum of all elements before the number.
Example: if we receive the array 10 20 30 40 20 30 40 and we receive on the next line the integer 20 we have to print the sum the elements 10 20 30 40, which is 100.
If no such number exists in the array – print “No occurrences were found!”.
Input
-
On the first line, you will receive the integer array
-
On the next line, you will receive the number, which you have to search
Output
If such number exists in the array – just print the sum.
Otherwise, print “No occurrences were found!”
Constraints
-
Only a single whitespace will be used for the separator.
-
The number will be integer in the interval [-2147483648…2147483647]
Examples
Input |
Output |
1 3 5 7 12 2 3 5 12 3 |
30 |
Input |
Output |
1 2 3 4 5 6 7 8 9 10 20 |
No occurrences were found! |
кодът ми е: https://pastebin.com/CBeYcSEr
Решението дава 85 /100. Променливата "sum" трябва да е long, защото според условието: "The number will be integer in the interval [-2147483648…2147483647]" и когато 2147483647 го събереш дори с 1 int се превърта. Ето моето решение:
https://pastebin.com/CaKA5Sna.