Advertisement
s010vey

Untitled

Apr 17th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. //Создать массив, в котором записать информацию о комнатах и телефонах учреждения:
  2. //название помещения, телефон. Вывести список помещений, в которых более одного телефона.
  3.  
  4. namespace lab1_1
  5. {
  6. class Program
  7. {
  8. struct Agency
  9. {
  10. private string name;
  11. private string[] numbers;
  12.  
  13. public Agency (string name, string[] numbers)
  14. {
  15. this.name = name;
  16. this.numbers = numbers;
  17. }
  18.  
  19. public static void ViewNumbers(Agency[] array)
  20. {
  21. foreach (Agency el in GetAgencies(array))
  22. {
  23. PrintRoom(el);
  24. }
  25. }
  26.  
  27. private static Agency[] GetAgencies(Agency[] array)
  28. {
  29. int count = 0, z = 0;
  30.  
  31. foreach (Agency el in array)
  32. {
  33. if (el.numbers.Length > 1)
  34. {
  35. count++;
  36. }
  37. }
  38.  
  39. Agency[] new_arr = new Agency[count];
  40.  
  41. for (var i = 0; i < array.Length; i++)
  42. {
  43. if (array[i].numbers.Length > 1)
  44. {
  45. new_arr[z] = array[i];
  46. z++;
  47. }
  48. }
  49.  
  50. return new_arr;
  51. }
  52.  
  53. private void PrintRoom(Agency el)
  54. {
  55. Console.Write(el.name + " -> ");
  56. foreach (string num in el.numbers)
  57. Console.Write(num + " ");
  58. Console.WriteLine();
  59. }
  60. }
  61.  
  62. static void Main(string[] args)
  63. {
  64. Agency[] array = new Agency[3];
  65. array[0] = new Agency ("Agency1", new string[2] { "+38(050)123-12-13", "+380(095)555-55-55" });
  66. array[1] = new Agency("God agency", new string[1] { "3" });
  67. array[2] = new Agency("Shop", new string[4] { "0800-100-100", "+38(050)134-12-13", "+38(050)222-11-33", "3000" });
  68. Agency.ViewNumbers(array);
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement