Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 13. Company Users
- Write a program that keeps information about companies and their employees.
- You will be receiving a company name and an employee's id, until you receive the command "End" command. Add each employee to the given company. Keep in mind that a company cannot have two employees with the same id.
- When you finish reading the data, order the companies by the name in ascending order.
- Print the company name and each employee's id in the following format:
- {companyName}
- -- {id1}
- -- {id2}
- -- {idN}
- Input / Constraints
- • Until you receive the "End" command, you will be receiving input in the format: "{companyName} -> {employeeId}".
- • The input always will be valid.
- Examples
- Input Output
- SoftUni -> AA12345 HP
- SoftUni -> BB12345 -- BB12345
- Microsoft -> CC12345 Microsoft
- HP -> BB12345 -- CC12345
- End SoftUni
- -- AA12345
- -- BB12345
- SoftUni -> AA12345 Lenovo
- SoftUni -> CC12344 -- XX23456
- Lenovo -> XX23456 Movement
- SoftUni -> AA12345 -- DD11111
- Movement -> DD11111 SoftUni
- End -- AA12345
- -- CC12344
- namespace _13CompanyUsers
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Program
- {
- static void Main()
- {
- var companies = new Dictionary<string, List<string>>();
- var inputLine = Console.ReadLine();
- while (inputLine != "End")
- {
- var inputArray = inputLine.Split(" -> ");
- var companyName = inputArray[0];
- var employeeID = inputArray[1];
- if (!companies.ContainsKey(companyName))
- {
- companies.Add(companyName, new List<string>());
- }
- if (!companies[companyName].Contains(employeeID))
- {
- companies[companyName].Add(employeeID);
- }
- inputLine = Console.ReadLine();
- }
- foreach (var item in companies.OrderBy(x => x.Key))
- {
- Console.WriteLine($"{item.Key}");
- foreach (var employeeID in item.Value)
- {
- Console.WriteLine($"-- {employeeID}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment