P1953 Yi Language
Description
Recently, the teacher has been studying Yi Language, a visual programming system for Windows, developed by Dalian Dayou Wutao Software Development Company, and possessing Chinese intellectual property rights. To learn this system better, the teacher deliberately uses it in practice to develop programs.
Today, the teacher encountered a problem: “When uploading testdata to KOJ, the testdata need to be renamed to the corresponding filenames.” For example, if the original testdata filenames are $\text{e0.in,\,e1.in\;...\;e9.in}$ and $\text{e0.out,\,e1.out\;...\;e9.out}$, then the teacher needs to rename all files to $\text{data1.in,\,data2.in\;...\;data10.in}$ and $\text{data1.out,\,data2.out\;...\;data10.out}$. The program interface is shown in the figure below:
*(Note: An image seems to be missing here, but it does not affect understanding of the problem.)*
Of course, the teacher is a novice at programming and is far less skilled than you, so the program is not good. Now the teacher would like you to help improve it.
In advance, the teacher will tell you the target filename format to be generated. For example, if the teacher tells you $\text{enger0.in}$ and $\text{ans}$, it means the basename of the input files in the target set is $\text{enger}$, the extension is $\text{in}$, and the index starts from $0$ and follows the basename. Naturally, the output filenames will be $\text{enger0.ans,\,enger1.ans\;...\;enger}x\text{.ans}$, where $x$ can be determined by counting how many original filenames the teacher provides. In addition, the teacher will also tell you the full names of all original input files, such as $\text{a1.txt,\,a2.txt\;...\;a}x\text{.txt}$. However, the teacher is careless. Do not expect the filenames to be given in ascending order of their indices, but the provided filenames are guaranteed to be correct and to follow general input/output filename conventions (the index number definitely appears at the end of the basename or at the end of the extension, and aside from this index number, no other digits will appear anywhere in either the original filenames or the target filenames).
Some original input/output filenames do not need changes to the basename or extension; only the file index needs to be changed. In this case, the teacher will first tell you a number $1$ (or $0$), meaning the basename and extension of the final target files should not be changed, and only the indices should be renumbered to start from $1$ (or $0$).
Input Format
The first line of input has two possibilities:
- Two strings, which specify the format of the final target filenames (the first string is the name of the first input file in the generated target set).
- A single number $1$ (or $0$), meaning the basename and extension do not need to change, and filenames only need to be renumbered starting from $1$ (or $0$).
Then follow $n$ lines ($1 \le n \le 10^5$). Each line contains two strings separated by a single space, representing the original input and output filenames, respectively. For all input and output filenames, the basename and extension are each at most $10$ characters, and the maximum file index does not exceed $2 \times 10^5$.
Output Format
Output $n$ lines. Each line contains two strings separated by a single space, representing the final target filenames: the first is the input filename, and the second is the output filename. Output in ascending order of index.
Explanation/Hint
Translated by ChatGPT 5