Hide

Problem B
Get Numbers From File

Write a program that extracts all numbers from a given text file. The results should be saved in a list and finally printed out in sorted order.

First, the program should ask the user for a file name, repeatedly until the user enters a name of a file that actually exists, as evidenced by the fact that it can be opened. The file will be located in the /src/ directory.

Input

The input consists of one or more line. At least one line will contain the name of a file that is accessible to the program.

To be specific, the input will consist of $n$ lines, where $n \ge 1$. For each $i$ with $1 \le i \le n$, line $i$ will contain a non-empty string, let us call it $s_i$ for future reference. At least one string $s_i$ will be the name of a file that is accessible to the program.

Note that in the samples below, the content of the files is not shown. See the provided text files for more information. The input files will consist of $0$ or more lines, containing a sequence of words and numbers separated by spaces. Each word will be made up of letters from the English alphabet, parentheses and punctuation, but there will never be numerical digits mixed into the words. Any numbers will always stand on their own, separated from the rest of the text by spaces or new line characters.

Output

The output should consist of $m$ lines, with $m \ge 1$, as described below.

For each $i$ with $1 \le i < m$, line $i$ of the output should read:

  • {$s_i$} not found! Please try again.

Finally, the last line should contain an ordered list of all numbers found in the file $s_m$, separated by commas and surrounded by square brackets.

As soon as the program receives a name of a file that it can open, it should stop asking for input and process the file. Note that this means $m$ could be less than $n$, but it should always be the case that $m \le n$.

Sample Input 1 Sample Output 1
Arc of the covenant
Aristotle's second book of Poetics
Confucius' Classic of Music
Book of Thoth
Amelia Earhart
Holy grail
Oceanic Airlines Flight 815
number_text.txt
Arc of the covenant not found! Please try again.
Aristotle's second book of Poetics not found! Please try again.
Confucius' Classic of Music not found! Please try again.
Book of Thoth not found! Please try again.
Amelia Earhart not found! Please try again.
Holy grail not found! Please try again.
Oceanic Airlines Flight 815 not found! Please try again.
[1, 3, 5, 7, 10, 77]
Sample Input 2 Sample Output 2
number_text_alternative.txt
number_text.txt
[1, 3, 15, 734]
Sample Input 3 Sample Output 3
yet_another_number_text.txt
[0, 1]
Sample Input 4 Sample Output 4
test_file_02
test_file_02.txt
test_file_02 not found! Please try again.
[698, 1099, 2155, 4955, 6153, 6722, 7824, 8384, 9454, 9947]

Please log in to submit a solution to this problem

Log in