Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Dynamic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Problem_7.Inventory_Matcher
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- int number = int.Parse(Console.ReadLine());
- bool isInList = Array.IndexOf(arr, number) != -1;
- if (isInList)
- {
- int lastIndex = Array.LastIndexOf(arr, number);
- int sum = arr.Take(lastIndex).Sum();
- Console.WriteLine(sum);
- }
- else
- {
- Console.WriteLine("No occurrences were found!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement