← 返回 microsoft 的题目列表In-Memory SQL with CSV Initialization
类型:online_judge
Problem: Implement a Simplified In-Memory SQL Engine (with CSV Initialization)
Implement an in-memory database that can initialize a table from a CSV string and execute a few SQL-like operations.
Input
Read from stdin:
Line 1: a CSV string csv (may contain quotes/escapes) representing the table
Line 2: integer q, the number of subsequent commands
Next q lines: one command per line
CSV Rules
The CSV encodes a 2D table:
First row contains column names
Remaining rows are data rows
Fields are separated by commas
A field may be wrapped in double quotes "
When quoted, the field may contain commas
Inside a quoted field, "" represents a literal double quote character "
You must implement parse_csv(csv: str) -> List[List[str]] yourself.
Supported Commands (minimum viable subset)
SELECT <col1,col2,...> WHERE <col>=<value>
Filter rows by equality condition
Output selected columns joined by commas, one row per line
INSERT <comma-separated-values>
Insert one row (must match the number of columns)
DELETE WHERE <col>=<value>
Delete all rows matching the equality condition
Output
Print results for each SELECT. Other commands produce no output.
Constraints
Total rows and commands up to 1e5
Aim for good time complexity
Sample Tests
(see Chinese version)
Example
Input
name,age,city
3
SELECT name WHERE city=New York
INSERT "Charlie",22,"New York"
SELECT name,age WHERE city=New York
Output
Alice
Alice,30
Charlie,22