Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- class Program
- {
- static void Main()
- {
- var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
- var num = int.Parse(Console.ReadLine());
- int arrLenght = arr.Length;
- int lastIndex = 0;
- int sum = 0;
- bool noNumber = true;
- for (int i = 0; i < arrLenght; i++)
- {
- if (arr[i] == num)
- {
- noNumber = false;
- lastIndex = i;
- }
- }
- if (noNumber == false)
- {
- for (int i = 0; i < lastIndex; i++)
- {
- sum += arr[i];
- }
- Console.WriteLine(sum);
- }
- else if (noNumber == true)
- {
- Console.WriteLine("No occurrences were found!");
- }
- else if(lastIndex == 0)
- {
- Console.WriteLine(sum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement