Advertisement
braveheart1989

SumOfCertainNum

Apr 5th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _11.Problem11
  8. {
  9.     class SumOfCertainNum
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.            
  14.             List<int> array = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  15.             int s = int.Parse(Console.ReadLine());
  16.             List<int> sequence = new List<int>();
  17.             int currSum = 0;
  18.             int maxSum = 0;
  19.  
  20.             for (int i = 0; i < array.Count-1; i++)
  21.             {
  22.                 currSum += array[i] + array[i+1];
  23.                 if (currSum > s)
  24.                 {
  25.                     while (currSum > s)
  26.                     {
  27.                         array.RemoveAt(array[i]);
  28.                         currSum = currSum - array[i];
  29.                     }
  30.                     if (currSum == s)
  31.                     {
  32.                         sequence.Add(array[i]);
  33.                         //sequence += currSum + " ";
  34.                     }
  35.                 }
  36.             }
  37.             Console.WriteLine(string.Join(" ", sequence));
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement