Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.IO;
- using Max - LOX;
- namespace KT2
- {
- internal class Tag
- {
- public string petName { get; protected set; }
- public long ownerPN { get; protected set; }
- public Tag(string petName, string ownerPN)
- {
- this.petName = petName;
- this.ownerPN = Convert.ToInt64(ownerPN);
- }
- public virtual void PrintInfo()
- {
- Console.WriteLine("Кличка: {0}, Телефон владельца: {1}", petName, ownerPN);
- }
- }
- class NewTag : Tag
- {
- public long registryPN { get; protected set; }
- public NewTag(string petName, string ownerPN, string registryPN) : base(petName, ownerPN)
- {
- this.registryPN = Convert.ToInt64(registryPN);
- }
- public override void PrintInfo()
- {
- Console.WriteLine("Кличка: {0}, Телефон владельца: {1}, Отдел регистрации: {2}", petName, ownerPN, registryPN);
- }
- }
- class Program
- {
- // СРАВНИВАЕМ ИМЕНА ПИТОМЦЕВ ПО АЛФАВИТУ
- public static int Comparer(Tag x, Tag y)
- {
- return string.Compare(x.petName, y.petName);
- }
- private static void Main()
- {
- StreamReader read = new StreamReader("a.txt");
- int regsize;
- string[] input;
- regsize = Convert.ToInt32(read.ReadLine());
- Tag[] register = new Tag[regsize];
- // ВВОДИМ ИНФУ
- for (int i = 0; i < regsize; i++)
- {
- input = read.ReadLine().Split();
- if(input.Length == 2) register[i] = new Tag(input[0], input[1]);
- else register[i] = new NewTag(input[0], input[1], input[2]);
- }
- // ВЫВОДИМ ВСЮ ИНФУ
- for (int i = 0; i < regsize; i++)
- {
- Console.Write("{0}) ", i+1);
- register[i].PrintInfo();
- }
- // ИЩЕМ ТЕЛЕФОН ВЛАДЕЛЬЦА
- bool found = false;
- string nameSearch;
- nameSearch = Console.ReadLine();
- for (int i = 0; i < regsize && !found; i++)
- {
- if (register[i].petName == nameSearch)
- {
- found = true;
- Console.WriteLine("Пробили телефончик! {0}", register[i].ownerPN);
- }
- }
- if(!found) Console.WriteLine("Не пробили :(");
- // ИЩЕМ НОВЫЕ БИРКИ
- foreach (Tag tag in register)
- {
- if (tag is NewTag)
- {
- Console.WriteLine("Ого, этот тег новый");
- tag.PrintInfo();
- }
- }
- // СОРТИРУЕМ ПО СВОЕМУ СОРТИРАТОРУ
- Array.Sort(register, Comparer);
- for (int i = 0; i < regsize; i++)
- {
- Console.Write("{0}) ", i+1);
- register[i].PrintInfo();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement