← 返回 anthropic 的题目列表RecipeManager Implementation
类型:online_judge
Implement a RecipeManager to support CRUD operations, search, sorting, user validation, and version control. Detailed requirements are as follows:
Level 1: CRUD Operations
Support adding, reading, updating, and deleting recipes.
Adding and updating operations are case-insensitive and must not allow duplicate recipe names.
Level 2: Search and Sort
Implement search functionality based on the recipe name.
Sort by the number of ingredients in ascending order, and by ID in ascending order if the ingredients count is the same.
Level 3: User System
Implement a user system where the edit_recipe requires validation of a user_id.
Level 4: Version Control
Updates to recipes do not overwrite old versions but append a new version to history.
Rollback creates a copy of an old version as a new one, ensuring recipe name conflicts are checked.
The program should accept and output JSON formatted data. A possible JSON input structure is:
{
"operation": "add",
"recipe": {
"name": "Spaghetti Bolognese",
"ingredients": ["spaghetti", "meat", "tomato"]
}
}
Test cases include scenarios such as creating, modifying, deleting, searching, and sorting recipes, validating user IDs, and rolling back versions.
Example
Input
{"operation": "add", "recipe": {"name": "Spaghetti Bolognese", "ingredients": ["spaghetti", "meat", "tomato"]}}