LachezarNinkov

Grab and Go

Sep 27th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace GrabAndGo
  5. {
  6.     class GrabAndGo
  7.     {
  8.         static void Main()
  9.         {
  10.             long[] numbers = Console.ReadLine()
  11.                                    .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  12.                                    .Select(long.Parse)
  13.                                    .ToArray();
  14.  
  15.             long fix = long.Parse(Console.ReadLine());
  16.             long index = 0;
  17.             long sum = 0;
  18.  
  19.             for (int i = 0; i < numbers.Length; i++)
  20.             {
  21.                 if (numbers[i] == fix)
  22.                 {
  23.                     index = i;
  24.                 }
  25.             }
  26.             for (int i = 0; i < index; i++)
  27.             {
  28.                 sum += numbers[i];
  29.             }
  30.             if (sum == 0)
  31.             {
  32.                 Console.WriteLine("No occurrences were found!");
  33.             }
  34.             else
  35.             {
  36.                 Console.WriteLine(sum);
  37.             }
  38.         }
  39.     }
  40. }
Add Comment
Please, Sign In to add comment