Guest User

Untitled

a guest
Aug 19th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace P04_GrabAndGo
  5. {
  6.     class P04_GrabAndGo
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             var numArray = Console.ReadLine()
  11.                 .Split(' ')
  12.                 .Select(long.Parse)
  13.                 .ToArray();
  14.             var findLastNum = long.Parse(Console.ReadLine());
  15.             if (numArray.Contains(findLastNum))
  16.             {
  17.                 int index = 0;
  18.                 for (int i = 0; i < numArray.Length; i++)
  19.                 {
  20.                     if (numArray[i] == findLastNum)
  21.                     {
  22.                         index = i;
  23.                     }
  24.                 }
  25.                 Console.WriteLine(
  26.                     numArray
  27.                     .Take(index)
  28.                     .Sum()
  29.                     );
  30.             }
  31.             else
  32.             {
  33.                 Console.WriteLine("No occurrences were found!");
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment