P9680 string[_view]
Background
C++'s string class is a powerful string class. However, because its string algorithms are tied to its memory management mechanism, it is inefficient when dealing with C-style strings.
To solve this problem, the C++17 standard introduced the string_view type, separating memory management from string algorithms, thus better adapting to processing C-style strings.
Description
You need to simulate a simple C++ program. Each line of the program must be in one of the following two forms:
- `string ();`
- `string_view ();`
Here, `variable-name` is the declared variable name (guaranteed not to have appeared before, and its length does not exceed $10$). `initializer` is the content used to initialize this variable, which can be:
- A string literal, i.e., a string enclosed in double quotes (in the form `"abc"`).
- A previously appeared variable name `source`. In this case, you should assign the string corresponding to `source` to `variable-name`.
Specifically, assigning any string $s$ to type string will perform $|s|$ character copies, while assigning to type string_view will not copy any characters. Here, $|s|$ is the length of string $s$.
You need to compute the total number of character copies in the program.
Input Format
The first line contains an integer $L$, representing the number of lines in the program.
In the next $L$ lines, a piece of code is given.
Output Format
Output an integer, representing the total number of character copies.
Explanation/Hint
For each test case, it is guaranteed that the length of the code does not exceed $10^4$ (excluding newline characters).
It is guaranteed that the string literals (excluding the surrounding quotes) and variable names contain only Latin letters, and the given code strictly satisfies the requirements of the problem.
### Subtasks
| # | Special Property | Score |
| :--: | :-----------------------------: | :---: |
| 0 | Sample | 0 |
| 1 | All variables are string_view | 10 |
| 2 | Only string literals are used | 20 |
| 3 | - | 70 |
---
Good news: GCC 9.3.0 supports string_view.
Bad news: NOI does not enable C++17.
Translated by ChatGPT 5