Hide

Problem B
Countries

Write a program that reads from a file, in this case named "countries.txt". An example of such a file is provided alongside the starter code. It is guaranteed that the file will exist and is accessible by the name "/src/countries.txt".

The program should find all countries listed in the file that end with a given suffix. Note that the comparison should be case sensitive.

Submission instructions

Note that we are NOT testing any function specifically, so your solution must handle the input and output itself!

It is a good idea for you to break the program down into bite-sized parts and implement each part as a function, because it makes it easier to develop and understand the program, but the structure of your code will not be tested, only what outputs it produces given certain inputs.

Input

The input consists of one line containing a string $s$ representing the suffix to search for, e.g. "land".

For your informatoin, in the test cases, $s$ will consist of $1$ to $50$ symbols. Each symbol in $s$ will be a digit or letter in the English alphabet. You do not need to validate the input, or refuse other input, this is just to inform you that you do not need to worry about other kinds of input.

Output

Let $N$ be the number of countries with the given suffix. Then the output should consist of $N+1$ lines. The first $N$ lines should each one contain the name of a country ending in the given suffix. You should output the names in the same order as they appear in the file. Finally, the last line should contain the string
{N} countries with suffix {s} in total.

Sample Input 1 Sample Output 1
land
Finland
Iceland
Republic of Ireland
New Zealand
Poland
Swaziland
Switzerland
Thailand
8 countries with suffix land in total.
Sample Input 2 Sample Output 2
ia
Albania
Algeria
Armenia
Australia
Austria
Bolivia
Bulgaria
Cambodia
Colombia
Croatia
Estonia
Ethiopia
Gambia
Georgia
India
Indonesia
Latvia
Liberia
Lithuania
Macedonia
Malaysia
Mauritania
Micronesia
Mongolia
Namibia
Nigeria
Romania
St Lucia
Saudi Arabia
Serbia
Slovakia
Slovenia
Somalia
Syria
Tanzania
Tunisia
Zambia
37 countries with suffix ia in total.
Sample Input 3 Sample Output 3
thereisprobablynocountrywiththissuffix
0 countries with suffix thereisprobablynocountrywiththissuffix in total.

Please log in to submit a solution to this problem

Log in