Teo_Yanchev

C# Fundamentals - 03. ConcatList - MidExam 30.06.2020 Group 1

Oct 8th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5.  
  6. namespace _30._06._2019_Mid_Exam_Group_1
  7. {
  8. class ContactList
  9. {
  10. static void Main(string[] args)
  11. {
  12. List<string> contactList = Console.ReadLine()
  13. .Split(' ')
  14. .ToList();
  15.  
  16. while (true)
  17. {
  18. string[] instructions = Console.ReadLine().Split(' ').ToArray();
  19. string command = instructions[0];
  20.  
  21. if (command == "Add")
  22. {
  23. string contact = instructions[1];
  24. int index = int.Parse(instructions[2]);
  25.  
  26. if (!contactList.Contains(contact))
  27. {
  28. contactList.Add(contact);
  29. }
  30. else
  31. {
  32. if (0 <= index && index <= contactList.Count - 1)
  33. {
  34. contactList.Insert(index, contact);
  35. }
  36. }
  37. }
  38. else if (command == "Remove")
  39. {
  40. int index = int.Parse(instructions[1]);
  41. if (0 <= index && index <= contactList.Count - 1)
  42. {
  43. contactList.RemoveAt(index);
  44. }
  45. }
  46. else if (command == "Export")
  47. {
  48. int startIndex = int.Parse(instructions[1]);
  49. int count = int.Parse(instructions[2]);
  50.  
  51. if (0 <= startIndex && startIndex <= contactList.Count - 1)
  52. {
  53. if (count > contactList.Count - 1)
  54. {
  55. for (int i = startIndex; i < contactList.Count; i++)
  56. {
  57. Console.Write($"{contactList[i]} ");
  58. }
  59. Console.WriteLine();
  60. }
  61. else
  62. {
  63. for (int i = startIndex; i < startIndex + count; i++)
  64. {
  65. Console.Write($"{contactList[i]} ");
  66. }
  67. Console.WriteLine();
  68. }
  69. }
  70. }
  71. else if (command == "Print")
  72. {
  73. string howToPrint = instructions[1];
  74. if (howToPrint == "Normal")
  75. {
  76. Console.Write("Contacts: ");
  77. Console.WriteLine(string.Join(' ', contactList));
  78. }
  79. else
  80. {
  81. contactList.Reverse();
  82. Console.Write("Contacts: ");
  83. Console.WriteLine(string.Join(' ', contactList));
  84. }
  85. break;
  86. }
  87. }
  88. }
  89. }
  90. }
  91.  
Advertisement
Add Comment
Please, Sign In to add comment