Two Words
Two friends usually play the following game:
They sit in front of the computer, and each one thinks of a word. Then, by pushing each other, they try to type the characters of the word each one has in mind, mixing the characters entered by one with those entered by the other. When they complete typing, they look at the result on the screen and find that the characters of the two words are so tangled that they have formed an unintelligible word that is not easy to separate in order to identify which character belongs to one friend's word and which belongs to the other's.
To help them, you need to write a program that distinguishes which of the characters in the word displayed on the screen belong to one friend's word and which belong to the other.
Input
The program will read the input data from a text file named INPUT.TXT, which will have the following structure:
The first and second lines will contain the words of the first and second friend, respectively. Each word consists only of capital Greek letters, and the number of characters in each word cannot be more than 40.
The third line will contain the tangled unintelligible word that appeared on the screen.
Output
The program will write the output data to a text file named OUTPUT.TXT, which will have the following structure:
The file will have one and only one line that contains a series of digits 1 and 2 without spaces between them, following this logic: the number of digits written should be equal to the number of characters in the third word of the input file. For each character of the third word, a digit in this line corresponds. If the character belongs to the word of the first friend, the digit 1 is set, while if the character belongs to the word of the second friend, the digit 2 is set.
Notes:
- Reading successively the characters marked with 1, we should get the word of the first friend, and reading successively the characters marked with 2, we should get the word of the second friend (without anagrams).
- We assume that the third word always contains the characters of the initial words and only those, without any space.
- The third word uniquely determines the words of the two friends.
Examples of Input-Output:
1o
STDIN (INPUT.TXT)
ΗΜΕΡΑ
ΠΟΛΗ
ΗΜΠΟΕΡΛΗΑ
STDOUT (OUTPUT.TXT)
112211221
2o
STDIN (INPUT.TXT)
ΠΑΤΑΤΑ
ΚΑΛΗΜΕΡΑ
ΚΠΑΤΑΑΤΛΗΑΜΕΡΑ
STDOUT (OUTPUT.TXT)
21111212212222
Notes
The executable file you will create should be named words.exe.
ATTENTION! You must strictly adhere to the names and structure of the files; otherwise, your answer will be considered incorrect.
Since your algorithm is evaluated automatically by specialized software, the following rules must be followed.
A. After writing the last line in the output file, the NEW LINE
character MUST NOT be written. For example, in Pascal, you can use "write" instead of "writeln." In "C" and "C++", after printing the characters of the last line, there MUST NOT be a \n
.
B. The program must NOT request ANY kind of "input" from the screen for execution. It should terminate correctly WITHOUT asking for user intervention (e.g., "Press enter to continue" is NOT acceptable).
C. The program must read the input file and create the output file in the SAME path from which the user's file is executed.
For example, in Pascal, the statement "assign(fin,'a:\input.txt');" is NOT acceptable. On the contrary, the statement "assign(Fin,'INPUT.TXT');" is acceptable.
D. The program must NOT require ANY auxiliary library to execute.
Comments