#C197. User Subscription Management System
User Subscription Management System
User Subscription Management System
In this problem, you are required to implement a simple user subscription management system. The system supports two operations:
-
update: Update the subscription status of a user based on the provided payment status.
Payment status mapping is as follows:
( \texttt{paid} \rightarrow \texttt{active} ), ( \texttt{failed} \rightarrow \texttt{inactive} ), and ( \texttt{pending} \rightarrow \texttt{pending} ).
If the input for the update operation is invalid (e.g. empty user ID or an invalid payment status), the update should not be performed. -
fetch: Retrieve the current subscription status of a user. If the user ID is invalid (i.e. empty) or never updated, the output should be
error
.
You must read the input from stdin
and write the output to stdout
.
inputFormat
The input begins with an integer T ((1 \leq T \leq 10^5)) which denotes the number of operations. Each of the following T lines represents an operation and can be one of the following two types:
-
update userId paymentStatus
-userId
: a non-empty string.
-paymentStatus
: one ofpaid
,failed
, orpending
. -
fetch userId
-userId
: a non-empty string. If missing or empty, it is considered invalid.
For update
operations, no output is produced. For fetch
operations, output the user's subscription status on a new line.
outputFormat
For each fetch
operation, output the user's subscription status. The status will be one of active
, inactive
, pending
if the user has been updated successfully. Otherwise, output error
if the userId is invalid or was never updated.## sample
6
update 12345 paid
fetch 12345
update 12346 failed
fetch 12346
update 12347 pending
fetch 12347
active
inactive
pending
</p>