#P1953. File Name Conversion

    ID: 15235 Type: Default 1000ms 256MiB

File Name Conversion

File Name Conversion

This problem requires you to convert a list of file names to a new naming scheme. The teacher provides either a target file name format or a mode indicator.

There are two scenarios:

Scenario 1: Custom Naming

You are given two strings. The first string represents the desired input file format, for example, enger0.in, from which you can extract the base name (here, enger), the starting number (0) and the input file extension (in). The second string is the desired output file extension (for example, ans). Then you are given an integer N and N original file names. Each original file name contains exactly one contiguous sequence of digits which appears either at the end of its main name or at the end of its extension. You must sort these file names in ascending order according to the integer value of the extracted digits. Then, starting from the starting number extracted from the target input file name, assign new sequential numbers (with no extra zero‐padding) to the files.

The new input file names are generated as follows:

base + new_number + "." + input_extension

and the new output file names are:

base + new_number + "." + output_extension

Scenario 2: Preserve Naming

If the teacher provides a single number (either 0 or 1) on the first line, it indicates that the base name and extension of the files should remain unchanged, and only the number should be re-assigned. In this case, the next line will be an integer N and then N original file names. Sort these names as before by the extracted number. For each sorted file, replace the original number with a new sequential number starting from the given mode number. The new file name is constructed by preserving the original non‐digit parts. In this mode, both input and output file names are identical.

Note on Extraction: Assume that in any file name, aside from the unique contiguous digit block, no other digits appear. If the file name contains a dot '.', split it into the part before and after the dot. If the part after the dot ends with digits, then the digits belong to the extension; otherwise, the digits at the end of the part before the dot are used.

The formulas used are in LaTeX format. For example, if the starting number is extracted from a string like \(\texttt{enger0.in}\), then the starting number is \(0\), and the new file names for \(N\) files are:

[ \text{Input files: } \texttt{enger0.in},,\texttt{enger1.in},,\ldots,,\texttt{enger}(N-1).in ]

[ \text{Output files: } \texttt{enger0.ans},,\texttt{enger1.ans},,\ldots,,\texttt{enger}(N-1).ans ]

Your program should read from standard input and write to standard output. The output should consist of two lines: the first line contains the new input file names (separated by a space) and the second line contains the new output file names (separated by a space).

inputFormat

The input begins with either:

  • Scenario 1 (Custom Naming):
    Line 1: A string representing the desired input file name format (e.g. enger0.in).
    Line 2: A string representing the desired output file extension (e.g. ans).
    Line 3: An integer \(N\) representing the number of test files.
    Next \(N\) lines: Each line contains one original file name.
  • Scenario 2 (Preserve Naming):
    Line 1: A single digit (0 or 1).
    Line 2: An integer \(N\).
    Next \(N\) lines: Each line contains one original file name.

Each original file name is guaranteed to be valid and contains exactly one contiguous block of digits that appears at the end of its main name or the extension.

outputFormat

Output two lines:

  • The first line contains all the newly generated input file names separated by a single space.
  • The second line contains all the newly generated output file names separated by a single space.

sample

enger0.in
ans
4
e10.in
e3.in
e1.in
e7.in
enger0.in enger1.in enger2.in enger3.in

enger0.ans enger1.ans enger2.ans enger3.ans

</p>