Advertisement
nikolayneykov

Untitled

Mar 17th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04Songs
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int numberOfSongs = int.Parse(Console.ReadLine());
  12.             List<Song> songs = new List<Song>();
  13.  
  14.             for (int i = 1; i <= numberOfSongs; i++)
  15.             {
  16.                 var data = Console.ReadLine().Split("_");
  17.  
  18.                 string type = data[0]; // set the type of song
  19.                 string name = data[1]; // set the name of song
  20.                 string time = data[2]; // set the time of song
  21.  
  22.                 Song song = new Song(type, name, time); // create new object from the class Song
  23.  
  24.                 songs.Add(song);
  25.             }
  26.  
  27.             string typeList = Console.ReadLine();
  28.             string result = string.Empty;
  29.             if (typeList == "all")
  30.             {
  31.                 result += string.Join("\n", songs.Select(x => x.Name));
  32.             }
  33.             result += string.Join("\n", songs.Where(x => x.TypeList == typeList).Select(x => x.Name));
  34.             Console.WriteLine(result);
  35.         }
  36.     }
  37.  
  38.     class Song
  39.     {
  40.         // fields
  41.         public string TypeList { get; set; }
  42.         public string Name { get; set; }
  43.         public string Time { get; set; }
  44.  
  45.         public Song(string typeList, string name, string time) // constructor
  46.         {
  47.             TypeList = typeList;
  48.             Name = name;
  49.             Time = time;
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement