Advertisement
Ilitid

Untitled

Mar 27th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.29 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.IO;
  4. using Max - LOX;
  5.  
  6. namespace KT2
  7. {
  8.     internal class Tag
  9.     {
  10.         public string petName { get; protected set; }
  11.         public long ownerPN { get; protected set; }
  12.  
  13.         public Tag(string petName, string ownerPN)
  14.         {
  15.             this.petName = petName;
  16.             this.ownerPN = Convert.ToInt64(ownerPN);
  17.         }
  18.  
  19.         public virtual void PrintInfo()
  20.         {
  21.             Console.WriteLine("Кличка: {0}, Телефон владельца: {1}", petName, ownerPN);
  22.         }
  23.     }
  24.  
  25.     class NewTag : Tag
  26.     {
  27.         public long registryPN { get; protected set; }
  28.  
  29.         public NewTag(string petName, string ownerPN, string registryPN) : base(petName, ownerPN)
  30.         {
  31.             this.registryPN = Convert.ToInt64(registryPN);
  32.         }
  33.  
  34.         public override void PrintInfo()
  35.         {
  36.             Console.WriteLine("Кличка: {0}, Телефон владельца: {1}, Отдел регистрации: {2}", petName, ownerPN, registryPN);
  37.         }
  38.     }
  39.  
  40.     class Program
  41.     {
  42.         // СРАВНИВАЕМ ИМЕНА ПИТОМЦЕВ ПО АЛФАВИТУ
  43.         public static int Comparer(Tag x, Tag y)
  44.         {
  45.             return string.Compare(x.petName, y.petName);
  46.         }
  47.        
  48.         private static void Main()
  49.         {
  50.             StreamReader read = new StreamReader("a.txt");
  51.             int regsize;
  52.             string[] input;
  53.  
  54.             regsize = Convert.ToInt32(read.ReadLine());
  55.             Tag[] register = new Tag[regsize];
  56.            
  57.             // ВВОДИМ ИНФУ
  58.             for (int i = 0; i < regsize; i++)
  59.             {
  60.                 input = read.ReadLine().Split();
  61.                 if(input.Length == 2) register[i] = new Tag(input[0], input[1]);
  62.                 else register[i] = new NewTag(input[0], input[1], input[2]);
  63.             }
  64.  
  65.             // ВЫВОДИМ ВСЮ ИНФУ
  66.             for (int i = 0; i < regsize; i++)
  67.             {
  68.                 Console.Write("{0}) ", i+1);
  69.                 register[i].PrintInfo();
  70.             }
  71.  
  72.             // ИЩЕМ ТЕЛЕФОН ВЛАДЕЛЬЦА
  73.             bool found = false;
  74.             string nameSearch;
  75.             nameSearch = Console.ReadLine();
  76.             for (int i = 0; i < regsize && !found; i++)
  77.             {
  78.                 if (register[i].petName == nameSearch)
  79.                 {
  80.                     found = true;
  81.                     Console.WriteLine("Пробили телефончик! {0}", register[i].ownerPN);
  82.                 }
  83.             }
  84.             if(!found) Console.WriteLine("Не пробили :(");
  85.  
  86.             // ИЩЕМ НОВЫЕ БИРКИ
  87.             foreach (Tag tag in register)
  88.             {
  89.                 if (tag is NewTag)
  90.                 {
  91.                     Console.WriteLine("Ого, этот тег новый");
  92.                     tag.PrintInfo();
  93.                 }
  94.             }
  95.            
  96.             // СОРТИРУЕМ ПО СВОЕМУ СОРТИРАТОРУ
  97.             Array.Sort(register, Comparer);
  98.            
  99.             for (int i = 0; i < regsize; i++)
  100.             {
  101.                 Console.Write("{0}) ", i+1);
  102.                 register[i].PrintInfo();
  103.             }
  104.            
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement