Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Exercise
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> wagons = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToList();
- int maxNumberOfPassenger = int.Parse(Console.ReadLine());
- string line = Console.ReadLine();
- while (line != "End")
- {
- List<string> command = line.Split().ToList();
- if (command[0] == "Add")
- { wagons.Add(int.Parse(command[1])); }
- else
- {
- int current = int.Parse(command[0]);
- FirstPossibleWagon(wagons, maxNumberOfPassenger, current);
- }
- line = Console.ReadLine();
- }
- Console.WriteLine(String.Join(" ",wagons));
- }
- static void FirstPossibleWagon(List<int> wagons, int maxNumberOfPassenger, int current)
- {
- for (int i = 0; i <wagons.Count; i++)
- {
- if (wagons[i] + current <= maxNumberOfPassenger
- )
- { int total = wagons[i] + current;
- wagons[i] = total;
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment