Advertisement
nikolayneykov

Untitled

Mar 17th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 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.             if (typeList == "all")
  29.             {
  30.                 songs.ForEach(s => Console.WriteLine(s.Name));
  31.             }
  32.  
  33.             songs.Where(x => x.TypeList == typeList).ToList().ForEach(s => Console.WriteLine(s.Name));
  34.         }
  35.     }
  36.  
  37.     class Song
  38.     {
  39.         // fields
  40.         public string TypeList { get; set; }
  41.         public string Name { get; set; }
  42.         public string Time { get; set; }
  43.  
  44.         public Song(string typeList, string name, string time) // constructor
  45.         {
  46.             TypeList = typeList;
  47.             Name = name;
  48.             Time = time;
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement