Quantcast
Channel: C#タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9707

お料理.cs

$
0
0
main.cs using System; using System.Collections.Generic; class Program { static Osaihu osaihu = new(100); static Dictionary<string, Guzai> supermarket = loadSuper(); static Dictionary<string, List<string>> recipe = loadRecipes(); static Nabe Main(string[] args) { Console.WriteLine("お料理開始!"); if (args.Length == 0) return null; if (recipe.TryGetValue(args[0], out var list)) { var bag = shopping(list, osaihu); Nabe nabe = new(); nabe.AddAll(bag); nabe.Nikomu(100); return nabe; } return null; } static List<Guzai> shopping(List<string> list, Osaihu osaihu) { List<Guzai> cart = new(); foreach (var item in list) { if (supermarket.TryGetValue(item, out var guzai)) { cart.Add(guzai); } else { cart.Add(null); } } List<Guzai> bag = new(); int sum = 0; foreach (var item in cart) { sum += item.price; bag.Add(item); } osaihu.Withdraw(sum); return bag; } } osaihu.cs class Osaihu { int money; public Osaihu(int m) { money = m; } public void Add(int m) { money += m; } public void Withdraw(int m) { money -= m; } } guzai.cs enum GuzaiState { packed, unpacked, cutted, } class Guzai { public string name { get; } public int price { get; } public double tempreture { get; set; } const double DEFAULT_TEMPRETURE = 10; GuzaiState state = GuzaiState.packed; public Guzai(string name, int price, double tempreture = DEFAULT_TEMPRETURE) { this.name = name; this.price = price; this.tempreture = tempreture; } } nabe.cs class Nabe { List<Guzai> contents = new(); public void Add(Guzai guzai) { contents.Add(guzai); } public void AddAll(List<Guzai> guzais) { contents = guzais; } public void Nikomu(double min) { foreach (var item in contents) { item.tempreture += min * 1.5; } } }

Viewing all articles
Browse latest Browse all 9707

Trending Articles