Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Lists
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
- int capacity = int.Parse(Console.ReadLine());
- string command =Console.ReadLine();
- while(command!="end")
- {
- string[] tokens = command.Split();
- switch(tokens[0])
- {
- case "Add":
- int number = int.Parse(tokens[1]);
- numbers.Add(number);
- break;
- default:
- number = int.Parse(tokens[0]);
- FindWagon(numbers, number, capacity);
- break;
- }
- command = Console.ReadLine();
- }
- Console.WriteLine(String.Join(" ", numbers));
- }
- private static void FindWagon(List<int> numbers, int number, int capacity)
- {
- for (int i = 0; i < numbers.Count; i++)
- {
- if(numbers[i]+number<=capacity)
- {
- numbers[i] = numbers[i] + number;
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement