Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Program
- {
- static void Main(string[] args)
- {
- List<Song> playlist = new List<Song>();
- int count = int.Parse(Console.ReadLine());
- for (int index = 0; index < count; index++)
- {
- try
- {
- string[] inputArr = Console.ReadLine()
- .Split(';', StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- string songName = inputArr[1];
- string singerName = inputArr[0];
- string lenght = inputArr[2];
- string[] lengthArr = lenght.Split(':').ToArray();
- int minutes;
- int seconds;
- if (int.TryParse(lengthArr[0], out minutes) && int.TryParse(lengthArr[1], out seconds))
- {
- Song song = new Song(singerName, songName, minutes, seconds);
- playlist.Add(song);
- Console.WriteLine("Song added.");
- }
- else
- {
- throw new InvalidSongLengthException();
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- }
- int playlistLenghtInSecs = playlist.Sum(p => p.SongLength);
- TimeSpan time = TimeSpan.FromSeconds(playlistLenghtInSecs);
- string str = time.ToString(@"hh\:mm\:ss");
- Console.WriteLine($"Songs added: {playlist.Count}");
- Console.WriteLine($"Playlist length: {time.Hours:D1}h {time.Minutes:D1}m {time.Seconds:D1}s");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement