← 返回 anthropic 的题目列表In-Memory Database
类型:online_judge
Design an in-memory database to support the following operations:
SET name value: Set the string name to the given value. If the name already exists, overwrite the old value. This operation does not return anything.
GET name: Return the value stored with the given name. If the name does not exist, return NULL.
UNSET name: Remove the value set for name. If the name does not exist, do nothing. This operation does not return anything.
NUMEQUALTO value: Return the number of names that have the given value. If no names have that value, return 0.
END: Terminate the operations.
Example:
> SET name Bob
> GET name
Bob
> SET name Alice
> GET name
Alice
> UNSET name
> GET name
NULL
> NUMEQUALTO Alice
0
> END
Please implement the above functionality in Python and test the response with different inputs.
Example
Input
SET name Bob\nGET name\nSET name Alice\nGET name\nUNSET name\nGET name\nNUMEQUALTO Alice\nEND
Output
Bob\nAlice\nNULL\n0