mirror of
https://github.com/Lendaia/oe-alga-feladatok.git
synced 2026-04-23 04:16:32 +01:00
wewewe
This commit is contained in:
@@ -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--;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
110
zh/Program.cs
Normal file
110
zh/Program.cs
Normal file
@@ -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<Category> Categories { get; set; } = new List<Category>();
|
||||
}
|
||||
public class Category
|
||||
{
|
||||
string Name { get; set; }
|
||||
public List<Product> Products = new List<Product>();
|
||||
}
|
||||
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<Category>)serializer.Deserialize(reader);
|
||||
}
|
||||
Shop shop = new Shop();
|
||||
shop.Category.AddRange(productackage.Categories);
|
||||
shop.SaveChanges();
|
||||
List<Product> expensive = new List<Product>();
|
||||
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<RequirementsAttribute>();
|
||||
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> ProductPackage { get; set; }
|
||||
public DbSet<Category> Category { get; set; }
|
||||
public DbSet<Product> Product { get; set; }
|
||||
public DbSet<Product> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
164
zh/products.xml
Normal file
164
zh/products.xml
Normal file
@@ -0,0 +1,164 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ProductPackage>
|
||||
<Categories>
|
||||
<Category>
|
||||
<Name>Coffee</Name>
|
||||
<Products>
|
||||
<Product><Sku>COF-1001</Sku><Name>Premium Arabica</Name><Price>12990</Price></Product>
|
||||
<Product><Sku></Sku><Name>Extra Dark Roast</Name><Price>9990</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Tea</Name>
|
||||
<Products>
|
||||
<Product><Sku>TEA-2001</Sku><Name>Green Tea</Name><Price>14990</Price></Product>
|
||||
<Product><Sku>TEA-2002</Sku><Name>Black Tea</Name><Price>8990</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Chocolate</Name>
|
||||
<Products>
|
||||
<Product><Sku>CHO-3001</Sku><Name>Dark Chocolate 85%</Name><Price>11990</Price></Product>
|
||||
<Product><Sku>CHO-3002</Sku><Name>Milk Chocolate</Name><Price>4990</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Biscuits</Name>
|
||||
<Products>
|
||||
<Product><Sku>BIS-4001</Sku><Name>Butter Cookies</Name><Price>10990</Price></Product>
|
||||
<Product><Sku>BIS-4002</Sku><Name>Chocolate Chip</Name><Price>9990</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Juice</Name>
|
||||
<Products>
|
||||
<Product><Sku>JUI-5001</Sku><Name>Orange Juice</Name><Price>6990</Price></Product>
|
||||
<Product><Sku>JUI-5002</Sku><Name>Mango Juice</Name><Price>10990</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Snacks</Name>
|
||||
<Products>
|
||||
<Product><Sku>SNA-6001</Sku><Name>Potato Chips</Name><Price>4990</Price></Product>
|
||||
<Product><Sku>SNA-6002</Sku><Name>Nachos Cheese</Name><Price>11990</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Water</Name>
|
||||
<Products>
|
||||
<Product><Sku>WAT-7001</Sku><Name>Mineral Water 0.5L</Name><Price>1990</Price></Product>
|
||||
<Product><Sku>WAT-7002</Sku><Name>Mineral Water 1.5L</Name><Price>2490</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Energy Drinks</Name>
|
||||
<Products>
|
||||
<Product><Sku>ENE-8001</Sku><Name>Energy Boost</Name><Price>11990</Price></Product>
|
||||
<Product><Sku>ENE-8002</Sku><Name>Zero Sugar Energy</Name><Price>10990</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Beer</Name>
|
||||
<Products>
|
||||
<Product><Sku>BEE-9001</Sku><Name>Lager Classic</Name><Price>5990</Price></Product>
|
||||
<Product><Sku></Sku><Name>Craft IPA</Name><Price>12990</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Wine</Name>
|
||||
<Products>
|
||||
<Product><Sku>WIN-10001</Sku><Name>Red Merlot</Name><Price>18990</Price></Product>
|
||||
<Product><Sku>WIN-10002</Sku><Name>White Chardonnay</Name><Price>17990</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Cheese</Name>
|
||||
<Products>
|
||||
<Product><Sku>CHE-11001</Sku><Name>Gouda</Name><Price>8990</Price></Product>
|
||||
<Product><Sku>CHE-11002</Sku><Name>Parmesan</Name><Price>13990</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Meat</Name>
|
||||
<Products>
|
||||
<Product><Sku>MEA-12001</Sku><Name>Beef Steak</Name><Price>25990</Price></Product>
|
||||
<Product><Sku>MEA-12002</Sku><Name>Pork Sausage</Name><Price>9990</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Fish</Name>
|
||||
<Products>
|
||||
<Product><Sku>FIS-13001</Sku><Name>Salmon Fillet</Name><Price>18990</Price></Product>
|
||||
<Product><Sku>FIS-13002</Sku><Name>Tuna Can</Name><Price>6990</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Vegetables</Name>
|
||||
<Products>
|
||||
<Product><Sku>VEG-14001</Sku><Name>Broccoli</Name><Price>4990</Price></Product>
|
||||
<Product><Sku>VEG-14002</Sku><Name>Carrots</Name><Price>2990</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Fruits</Name>
|
||||
<Products>
|
||||
<Product><Sku>FRU-15001</Sku><Name>Bananas</Name><Price>3990</Price></Product>
|
||||
<Product><Sku>FRU-15002</Sku><Name>Apples</Name><Price>4490</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Dairy</Name>
|
||||
<Products>
|
||||
<Product><Sku></Sku><Name>Whole Milk</Name><Price>2590</Price></Product>
|
||||
<Product><Sku>DAI-16002</Sku><Name>Yogurt</Name><Price>3290</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Bread</Name>
|
||||
<Products>
|
||||
<Product><Sku>BRE-17001</Sku><Name>Wholegrain Bread</Name><Price>6990</Price></Product>
|
||||
<Product><Sku>BRE-17002</Sku><Name>White Toast</Name><Price>5990</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Electronics</Name>
|
||||
<Products>
|
||||
<Product><Sku>ELE-18001</Sku><Name>Wireless Headphones</Name><Price>29990</Price></Product>
|
||||
<Product><Sku>ELE-18002</Sku><Name>Bluetooth Speaker</Name><Price>24990</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Books</Name>
|
||||
<Products>
|
||||
<Product><Sku>BOO-19001</Sku><Name>Programming in C#</Name><Price>15990</Price></Product>
|
||||
<Product><Sku>BOO-19002</Sku><Name>History of AI</Name><Price>18990</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
|
||||
<Category>
|
||||
<Name>Games</Name>
|
||||
<Products>
|
||||
<Product><Sku>GAM-20001</Sku><Name>Chess Set</Name><Price>8990</Price></Product>
|
||||
<Product><Sku></Sku><Name>Video Game Controller</Name><Price>21990</Price></Product>
|
||||
</Products>
|
||||
</Category>
|
||||
</Categories>
|
||||
</ProductPackage>
|
||||
16
zh/zh.csproj
Normal file
16
zh/zh.csproj
Normal file
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="9.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.10" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user