Created
August 28, 2019 20:09
-
-
Save HolyMonkey/164a6b05eb869781b4562985237f9fa2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bag | |
{ | |
public List<Item> Items; | |
public int MaxWeidth; | |
public void AddItem(string name, int count) | |
{ | |
int currentWeidth = Items.Sum(item => item.Count); | |
Item targetItem = Items.FirstOrDefault(item => item.Name == name); | |
if (targetItem == null) | |
throw new InvalidOperationException(); | |
if (currentWeidth + count > MaxWeidth) | |
throw new InvalidOperationException(); | |
targetItem.Count += count; | |
} | |
} | |
class Item | |
{ | |
public int Count; | |
public string Name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment