Advertisement
TeMePyT

Untitled

May 30th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Dynamic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Problem_7.Inventory_Matcher
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. int[] arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  15. int number = int.Parse(Console.ReadLine());
  16. bool isInList = Array.IndexOf(arr, number) != -1;
  17. if (isInList)
  18. {
  19. int lastIndex = Array.LastIndexOf(arr, number);
  20. int sum = arr.Take(lastIndex).Sum();
  21. Console.WriteLine(sum);
  22. }
  23. else
  24. {
  25. Console.WriteLine("No occurrences were found!");
  26. }
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement