#P9680. Simulate C++ String Copy Operations
Simulate C++ String Copy Operations
Simulate C++ String Copy Operations
You are given a program written in a simplified C++ syntax. Each line of the program is one of the following two forms:
string variable_name(initializer);
string_view variable_name(initializer);
Here, variable_name
is a unique identifier (its length is at most ) that has not appeared before. The initializer
is either:
- A string literal enclosed in double quotes (for example, "abc"), or
- A previously declared variable name (for example, source) which refers to the content of that variable.
When assigning a string value to a variable of type string
, the program performs exactly character copy operations (where is the length of the string). When assigning to a variable of type string_view
, no character copy is performed.
Your task is to calculate the total number of character copy operations performed by the program.
Input Format: The first line contains an integer indicating the number of lines in the program. Each of the following lines is a declaration in one of the two forms described above.
Output Format: Output a single integer, the total number of character copy operations performed throughout the program.
Note: When the initializer is a previously declared variable, the assigned string is exactly the content of that variable.
inputFormat
The input begins with an integer n representing the number of lines in the program.
Each of the next n lines contains a variable declaration in one of the following forms:
string variable_name(initializer);
string_view variable_name(initializer);
The initializer is either a string literal (enclosed in double quotes) or a previously declared variable name.
outputFormat
Print a single line containing the total number of character copy operations performed.
sample
3
string a("abc");
string_view b(a);
string c(b);
6
</p>