diff --git a/ALGA/Optimalizalas/08_DinamikusProgramozas.cs b/ALGA/Optimalizalas/08_DinamikusProgramozas.cs index 0eda9f8..f91ad93 100644 --- a/ALGA/Optimalizalas/08_DinamikusProgramozas.cs +++ b/ALGA/Optimalizalas/08_DinamikusProgramozas.cs @@ -33,14 +33,14 @@ namespace OE.ALGA.Optimalizalas { for (int j = 1; j <= problema.Wmax; j++) { - if (j <= problema.W[i - 1]) + if (j >= problema.W[i - 1]) { - F[i, j] = F[i - 1, j]; + int[] tomb = new int[] { (F[i - 1, j]), (F[i - 1, j - problema.W[i-1]] + Convert.ToInt32(problema.P[i-1])) }; + F[i, j] = tomb.Max(); } else { - int[] tomb = new int[] { (F[i - 1, j]), (F[i - 1, j - problema.W[i - 1]] + Convert.ToInt32(problema.P[i - 1])) }; - F[i, j] = tomb.Max(); + F[i, j] = F[i - 1, j]; } lepesszam++; } @@ -54,7 +54,7 @@ namespace OE.ALGA.Optimalizalas { return 0; } - return tablazat[problema.N - 1, problema.Wmax - 1]; + return tablazat[problema.N, problema.Wmax]; } public bool[] OptimalisMegoldas() { @@ -66,8 +66,8 @@ namespace OE.ALGA.Optimalizalas { if (tablazat[t, h] != tablazat[t - 1, h]) { - optimails[t] = true; - h = h - problema.W[t]; + optimails[t-1] = true; + h = h - problema.W[t-1]; } t--; } diff --git a/ALGA_heti_feladatok.sln b/ALGA_heti_feladatok.sln index 98c9072..86e2a93 100644 --- a/ALGA_heti_feladatok.sln +++ b/ALGA_heti_feladatok.sln @@ -16,6 +16,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sandbox", "Sandbox\Sandbox. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tesztek", "Tesztek\Tesztek.csproj", "{AFE58A8F-D9BA-4EBF-810D-F7E07E5A296C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "zh", "zh\zh.csproj", "{EABD26DD-3AE7-4941-BDFD-79862E7279F5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -42,6 +44,10 @@ Global {AFE58A8F-D9BA-4EBF-810D-F7E07E5A296C}.Debug|Any CPU.Build.0 = Debug|Any CPU {AFE58A8F-D9BA-4EBF-810D-F7E07E5A296C}.Release|Any CPU.ActiveCfg = Release|Any CPU {AFE58A8F-D9BA-4EBF-810D-F7E07E5A296C}.Release|Any CPU.Build.0 = Release|Any CPU + {EABD26DD-3AE7-4941-BDFD-79862E7279F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EABD26DD-3AE7-4941-BDFD-79862E7279F5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EABD26DD-3AE7-4941-BDFD-79862E7279F5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EABD26DD-3AE7-4941-BDFD-79862E7279F5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/zh/Program.cs b/zh/Program.cs new file mode 100644 index 0000000..a93c051 --- /dev/null +++ b/zh/Program.cs @@ -0,0 +1,110 @@ +using System.Reflection; +using System.Security.Cryptography.X509Certificates; +using System.Xml.Serialization; +using Castle.Components.DictionaryAdapter.Xml; +using Microsoft.EntityFrameworkCore; +using Microsoft.VisualBasic; + +namespace zh +{ + public class ProductPackage + { + public List Categories { get; set; } = new List(); + } + public class Category + { + string Name { get; set; } + public List Products = new List(); + } + public class Product + { + [Requirements(Requirement.RequiredNonEmpty)] + public string Sku { get; set; } + + public string Name { get; set; } + + [Requirements(Requirement.RequiredNonNegative)] + public int Price { get; set; } + } + public class Program + { + public static void Main() + { + ProductPackage productackage = new ProductPackage(); + XmlSerializer serializer = new XmlSerializer(typeof(ProductPackage)); + using (StreamReader reader = new StreamReader("zh/products.xml")) + { + productackage.Categories = (List)serializer.Deserialize(reader); + } + Shop shop = new Shop(); + shop.Category.AddRange(productackage.Categories); + shop.SaveChanges(); + List expensive = new List(); + foreach (Category category in productackage.Categories) + { + expensive.Concat(from x in category.Products + where x.Price > 10000 + select x); + } + } + } + public enum Requirement + { + RequiredNonEmpty, + RequiredNonNegative + } + public class RequirementsAttribute : Attribute + { + public Requirement Rule { get; set; } + public RequirementsAttribute(Requirement rule) + { + Rule = rule; + } + } + public class Validator + { + public static void Validate(Product product) + { + var t = product.GetType(); + var p = t.GetProperty("Sku"); + var a = p.GetCustomAttribute(); + var v = p.GetValue(product); + if (a.Rule == Requirement.RequiredNonEmpty) + { + if (v == null || (string)v == "") + { + throw new WrongProductException(); + } + } + else if(a.Rule == Requirement.RequiredNonNegative) + { + if ((int)v < 0) + { + throw new WrongProductException(); + } + } + } + } + public class WrongProductException : Exception + { + + } + public class Shop : DbContext + { + //public DbSet ProductPackage { get; set; } + public DbSet Category { get; set; } + public DbSet Product { get; set; } + public DbSet Expensive { get; set; } + public Shop() + { + Database.EnsureDeleted(); + Database.EnsureCreated(); + } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + string connStr = @"Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=Shopdb;Integrated Security=True;MultipleActiveResultSets=true"; + optionsBuilder.UseSqlServer(connStr); + base.OnConfiguring(optionsBuilder); + } + } +} diff --git a/zh/products.xml b/zh/products.xml new file mode 100644 index 0000000..afdd13c --- /dev/null +++ b/zh/products.xml @@ -0,0 +1,164 @@ + + + + + Coffee + + COF-1001Premium Arabica12990 + Extra Dark Roast9990 + + + + + Tea + + TEA-2001Green Tea14990 + TEA-2002Black Tea8990 + + + + + Chocolate + + CHO-3001Dark Chocolate 85%11990 + CHO-3002Milk Chocolate4990 + + + + + Biscuits + + BIS-4001Butter Cookies10990 + BIS-4002Chocolate Chip9990 + + + + + Juice + + JUI-5001Orange Juice6990 + JUI-5002Mango Juice10990 + + + + + Snacks + + SNA-6001Potato Chips4990 + SNA-6002Nachos Cheese11990 + + + + + Water + + WAT-7001Mineral Water 0.5L1990 + WAT-7002Mineral Water 1.5L2490 + + + + + Energy Drinks + + ENE-8001Energy Boost11990 + ENE-8002Zero Sugar Energy10990 + + + + + Beer + + BEE-9001Lager Classic5990 + Craft IPA12990 + + + + + Wine + + WIN-10001Red Merlot18990 + WIN-10002White Chardonnay17990 + + + + + Cheese + + CHE-11001Gouda8990 + CHE-11002Parmesan13990 + + + + + Meat + + MEA-12001Beef Steak25990 + MEA-12002Pork Sausage9990 + + + + + Fish + + FIS-13001Salmon Fillet18990 + FIS-13002Tuna Can6990 + + + + + Vegetables + + VEG-14001Broccoli4990 + VEG-14002Carrots2990 + + + + + Fruits + + FRU-15001Bananas3990 + FRU-15002Apples4490 + + + + + Dairy + + Whole Milk2590 + DAI-16002Yogurt3290 + + + + + Bread + + BRE-17001Wholegrain Bread6990 + BRE-17002White Toast5990 + + + + + Electronics + + ELE-18001Wireless Headphones29990 + ELE-18002Bluetooth Speaker24990 + + + + + Books + + BOO-19001Programming in C#15990 + BOO-19002History of AI18990 + + + + + Games + + GAM-20001Chess Set8990 + Video Game Controller21990 + + + + diff --git a/zh/zh.csproj b/zh/zh.csproj new file mode 100644 index 0000000..0d56680 --- /dev/null +++ b/zh/zh.csproj @@ -0,0 +1,16 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + +