Example #1
0
    public static void Main()
    {
        int n = NextInt;
        var a = new Section[n];
        var b = new Section[n];

        for (int i = 0; i < n; i++)
        {
            a[i] = new Section()
            {
                Begin = NextInt, End = NextInt
            };
            b[i] = new Section()
            {
                Begin = NextInt, End = NextInt
            };
        }
        var aDict = a.Select(x => x.Begin).Concat(a.Select(x => x.End)).Distinct().OrderBy(x => x).Select((elem, ind) => new { elem, ind }).ToDictionary(x => x.elem, x => x.ind);
        var bDict = b.Select(x => x.Begin).Concat(b.Select(x => x.End)).Distinct().OrderBy(x => x).Select((elem, ind) => new { elem, ind }).ToDictionary(x => x.elem, x => x.ind);

        for (int i = 0; i < n; i++)
        {
            a[i].Begin = aDict[a[i].Begin];
            a[i].End   = aDict[a[i].End];
            b[i].Begin = bDict[b[i].Begin];
            b[i].End   = bDict[b[i].End];
        }
        Console.WriteLine(Solve(aDict.Count, bDict.Count, a, b) && Solve(bDict.Count, aDict.Count, b, a) ? "YES" : "NO");
    }
Example #2
0
 /// <summary>
 /// Gets a list of Instrument objects filtered by a section
 /// </summary>
 /// <param name="selectedSection">A section to filter instruments by</param>
 /// <returns></returns>
 //public List<Instrument> GetInstruments(Section selectedSection)
 //{
 //    using (dbconn = new SqlConnection(Music.Properties.Settings.Default.orchestraConnection))
 //    {
 //        dbconn.Open();
 //        dbcomm = new SqlCommand(String.Format("select Instrument, Type from Instruments where Type = '{0}' order by Type asc",selectedSection.ToString()), dbconn);
 //        dbreader = dbcomm.ExecuteReader();
 //        List<Instrument> instruments = new List<Instrument>();
 //        while (dbreader.Read())
 //        {
 //            string instrumentName = dbreader["Instrument"].ToString();
 //            Section instrumentType;
 //            if (Enum.TryParse<Section>(dbreader["Type"].ToString(), true, out instrumentType))
 //                instruments.Add(new Instrument(instrumentName, instrumentType));
 //            else
 //                instruments.Add(new Instrument());
 //        }
 //        dbconn.Close();
 //        return instruments;
 //    }
 //}
 /// <summary>
 /// Gets a list of Instrument objects filtered by an array of Sections
 /// </summary>
 /// <param name="selectedSection">An array to filter instruments by</param>
 /// <returns></returns>
 public List<Instrument> GetInstruments(Section[] selectedSection)
 {
     try
     {
         using (dbconn = new SqlConnection(Music.Properties.Settings.Default.orchestraConnection))
         {
             dbconn.Open();
             //This command creates a sql string that checks for instruments of a type contained in the parameter list which is created by using a string join and some string formats
             dbcomm = new SqlCommand(String.Format("select Instrument, Type from Instruments where Type in({0}) order by Instrument asc", String.Join(",", selectedSection.Select(x => String.Format("'{0}'", x.ToString())).ToArray())), dbconn);
             dbreader = dbcomm.ExecuteReader();
             List<Instrument> instruments = new List<Instrument>();
             while (dbreader.Read())
             {
                 string instrumentName = dbreader["Instrument"].ToString();
                 Section instrumentType;
                 //This sneaky little section tries to parse the instrument value of the instrument by using the Enum.TryParse which returns a bool, if false there is a bad type and a default instrument replaces it
                 if (Enum.TryParse<Section>(dbreader["Type"].ToString(), true, out instrumentType))
                     instruments.Add(new Instrument(instrumentName, instrumentType));
                 else
                     instruments.Add(new Instrument());
             }
             return instruments;
         }
     }
     catch
     {
         throw new ArgumentException("Something has gone horribly, horribly wrong. Most likely my SQL instance is unreachable or down.");
     }
 }
Example #3
0
        /// <summary>
        /// Initializes data in the DataBase
        /// </summary>
        /// <param name="context">DB context</param>
        public static void Initial(BookStoreDbContext context)
        {
            if (!context.Books.Any())
            {
                context.Books.AddRange(Books.Select(c => c.Value));
            }

            if (!context.Sections.Any())
            {
                context.Sections.AddRange(Section.Select(c => c.Value));
            }

            if (!context.Carousels.Any())
            {
                context.Carousels.AddRange(Carousel.Select(c => c.Value));
            }

            context.SaveChanges();

            if (!context.Sections.FirstOrDefault().BookSection.Any()) //TODO: Fix this code...
            {
                context.Sections.FirstOrDefault(s => s.Title == "Discount books")
                ?.BookSection.Add(new BookSection()
                {
                    BookId    = context.Books.FirstOrDefault(s => s.Title == "C# 8.0 and .NET Core 3.0 - Modern Cross-Platform Development").Id,
                    SectionId = context.Sections.FirstOrDefault(s => s.Title == "Discount books").Id
                });
                context.Sections.FirstOrDefault(s => s.Title == "Discount books")
                ?.BookSection.Add(new BookSection()
                {
                    BookId    = context.Books.FirstOrDefault(s => s.Title == "Pro ASP.NET Core MVC 2, 7th ed. Edition").Id,
                    SectionId = context.Sections.FirstOrDefault(s => s.Title == "Discount books").Id
                });
                context.Sections.FirstOrDefault(s => s.Title == "Discount books")
                ?.BookSection.Add(new BookSection()
                {
                    BookId    = context.Books.FirstOrDefault(s => s.Title == "Pro C# 7: With .NET and .NET Core, 8th ed. Edition").Id,
                    SectionId = context.Sections.FirstOrDefault(s => s.Title == "Discount books").Id
                });
                context.Sections.FirstOrDefault(s => s.Title == "New books")
                ?.BookSection.Add(new BookSection()
                {
                    BookId    = context.Books.FirstOrDefault(s => s.Title == "C# in Depth, 4th Edition").Id,
                    SectionId = context.Sections.FirstOrDefault(s => s.Title == "New books").Id
                });
                context.Sections.FirstOrDefault(s => s.Title == "New books")
                ?.BookSection.Add(new BookSection()
                {
                    BookId    = context.Books.FirstOrDefault(s => s.Title == "ASP.NET Core in Action").Id,
                    SectionId = context.Sections.FirstOrDefault(s => s.Title == "New books").Id
                });
                context.Sections.FirstOrDefault(s => s.Title == "Subscriptions")
                ?.BookSection.Add(new BookSection()
                {
                    BookId    = context.Books.FirstOrDefault(s => s.Title == "Clean Code: A Handbook of Agile Software Craftsmanship").Id,
                    SectionId = context.Sections.FirstOrDefault(s => s.Title == "New books").Id
                });
                context.Sections.FirstOrDefault(s => s.Title == "Subscriptions").BookSection.Add(new BookSection()
                {
                    BookId    = context.Books.FirstOrDefault(s => s.Title == "Introduction to Algorithms, 3rd Edition").Id,
                    SectionId = context.Sections.FirstOrDefault(s => s.Title == "New books").Id
                });
            }

            context.SaveChanges();
        }