Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- //*Write a program, which categorizes information about a travel company.
- Companies have various vehicles planned for different cities. Every city has prepared several types of vehicles. Each vehicle type has a different capacity.
- Until you receive the command “ready”, you will receive all the cities the company offers holiday packages for, and their respective vehicle types + capacities in the format:
- • “{city}:{type}-{capacity},{type}-{capacity}…”
- An example city with its transportation options would look like this:
- • “Athens:bus-40,airplane-300,train-150”
- If a city is entered a second time, add all transport which hasn’t already been added and replace existing transports’ capacities with the new ones.
- After the “ready” command, you will start receiving groups for various cities in the format: “{city} {peopleCount}” until you receive “travel time!”.
- After that, calculate whether the group will have enough seats to accommodate the passengers and print the status per these conditions:
- If the group’s size is smaller than or equal to the combines seats in all the vehicles, print:
- • “{city} -> all {peopleCount} accommodated”
- If the group’s size is larger than the combines seats in all the vehicles, print:
- • “{city} -> all except {peopleCount - transportCapacities} accommodated”*//
- namespace Travel_company
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, Dictionary<string, int>> dict = new Dictionary<string, Dictionary<string, int>>();
- Dictionary<string, int> groups = new Dictionary<string, int>();
- string input = Console.ReadLine();
- while (input != "ready")
- {
- string[] toInput = input.Split(':').ToArray();
- string city = toInput[0];
- string[] token = toInput[1].Split(',').ToArray();
- if (!dict.ContainsKey(city))
- {
- dict.Add(city, new Dictionary<string, int>());
- }
- for (int i = 0; i < token.Length; i++)
- {
- string[] toAdd = token[i].Split('-').ToArray();
- string vehicle = toAdd[0];
- int capacity = int.Parse(toAdd[1]);
- if (!dict[city].ContainsKey(vehicle))
- {
- dict[city].Add(vehicle, capacity);
- }
- dict[city][vehicle] = capacity;
- }
- input = Console.ReadLine();
- }
- string ready = Console.ReadLine();
- while (ready != "travel time!")
- {
- string[] travel = ready.Split(' ').ToArray();
- string travelCity = travel[0];
- int travelCount = int.Parse(travel[1]);
- if (!groups.ContainsKey(travelCity))
- {
- groups.Add(travelCity, travelCount);
- }
- groups[travelCity] = travelCount;
- ready = Console.ReadLine();
- }
- foreach (KeyValuePair<string, int> group in groups)
- {
- int peopleCount = group.Value;
- var totalCapacityInEachCity = dict[group.Key].Values.Sum();
- if (peopleCount > 0 && peopleCount <= totalCapacityInEachCity)
- {
- Console.WriteLine($"{group.Key} -> all {peopleCount} accommodated");
- }
- else if (totalCapacityInEachCity > 0 && peopleCount > totalCapacityInEachCity)
- {
- Console.WriteLine($"{group.Key} -> all except {peopleCount - totalCapacityInEachCity} accommodated");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement