Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace ConsoleApplication2
- {
- class Program
- {
- static void Main(string[] args)
- {
- Album[] albums = new Album[10];
- Random r = new Random();
- Record[] shortestSongs = new Record[10];
- Record[] longestSongs = new Record[10];
- for (int i = 0; i < 10; i++)
- {
- Album album = new Album(i);
- for (int j = 0; j < 10; j++)
- {
- album.Tracks[j] = new Track(r.Next(30, 300));
- }
- albums[i] = album;
- }
- foreach (var item in albums)
- {
- shortestSongs[item.ID] = new Record(item.ID, item.Tracks.OrderBy(l => l.Length).Take(3).Sum(t => t.Length));
- longestSongs[item.ID] = new Record(item.ID, item.Tracks.OrderBy(l => l.Length).Reverse().Take(3).Sum(t => t.Length));
- }
- for (int i = 0; i < 10; i++)
- {
- Console.WriteLine("Album #{0}: Sum of Shortest Songs: {1} - Sum of Longest Songs: {2}", shortestSongs[i].AlbumID, shortestSongs[i].Length, longestSongs[i].Length);
- }
- Console.WriteLine("Shortest album is: #{0}", shortestSongs.OrderBy(s => s.Length).First().AlbumID);
- Console.WriteLine("Longest album is: #{0}", longestSongs.OrderBy(l => l.Length).Last().AlbumID);
- Console.ReadLine();
- }
- }
- class Album
- {
- public Track[] Tracks { get; private set; }
- public int ID { get; private set; }
- public Album(int id)
- {
- Tracks = new Track[10];
- ID = id;
- }
- }
- class Track
- {
- public int Length { get; private set; }
- public Track(int length)
- {
- Length = length;
- }
- }
- class Record
- {
- public int AlbumID { get; private set; }
- public int Length { get; private set; }
- public Record(int albumID, int length)
- {
- AlbumID = albumID;
- Length = length;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement