Advertisement
silvana1303

contact list

Jun 16th, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Threading;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     class Exam
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<string> names = Console.ReadLine().Split().ToList();
  14.  
  15.             string[] command = Console.ReadLine().Split().ToArray();
  16.  
  17.             while (command[0] != "Print")
  18.             {
  19.                 if (command[0] == "Add")
  20.                 {
  21.                     if (names.Contains(command[1]))
  22.                     {
  23.                         int index = int.Parse(command[2]);
  24.  
  25.                         if (index >= 0 && index < names.Count)
  26.                         {
  27.                             names.Insert(index, command[1]);
  28.                         }
  29.                     }
  30.                     else
  31.                     {
  32.                         names.Add(command[1]);
  33.                     }
  34.                 }
  35.                 if (command[0] == "Remove")
  36.                 {
  37.                     int index = int.Parse(command[1]);
  38.  
  39.                     if (index >= 0 && index < names.Count)
  40.                     {
  41.                         names.RemoveAt(index);
  42.                     }
  43.                 }
  44.                 if (command[0] == "Export")
  45.                 {
  46.                     int startIndex = int.Parse(command[1]);
  47.                     int count = int.Parse(command[2]);
  48.  
  49.                     if (count > names.Count)
  50.                     {
  51.                         count = names.Count - startIndex;
  52.                     }
  53.  
  54.                     List<string> export = names.GetRange(startIndex, count);
  55.                     Console.WriteLine(string.Join(" ", export));
  56.                 }
  57.  
  58.                 command = Console.ReadLine().Split().ToArray();
  59.             }
  60.  
  61.             if (command[1] == "Normal")
  62.             {
  63.                 Console.WriteLine($"Contacts: {string.Join(" ", names)}");
  64.             }
  65.             else
  66.             {
  67.                 names.Reverse();
  68.                 Console.WriteLine($"Contacts: {string.Join(" ", names)}");
  69.             }
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement