-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtask2.txt
58 lines (40 loc) · 2.31 KB
/
task2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Stage 2/6: Expand the search
Description
Now, let's make our search a little more complex. Let's write a program that performs multiple searches in multiple text lines.
Objectives
Write a program that reads text lines from the standard input and processes single-word queries. The program must output all lines that contain the string from the query. For this stage, this should include the case where the query string appears as a substring of one of the text lines. For example, the query "bc" should be found in a line containing "abcd".
You may choose what the text represents in your project. For example, each line may describe:
a person represented by the first name, the last name, and optionally an email;
an address of a building represented by the country, city, state, street, and zip code;
a book represented by its ISBN, title, author/authors, publisher, and so on.
You can use any of these options or come up with your own, because your search algorithm should work regardless of what the text actually represents.
Here is an example of a line. It contains three items: first name, last name, and this person's email.
Elsa Sanders [email protected]
In this example, all items are separated by spaces.
The search should ignore letter cases and all the extra spaces.
Firstly, the user should input a number N, which is a number of lines with data they are going to enter next. Then the user enters N lines with data. After that, the user enters a number M, which is a number of search queries. And after each query, the program should print the information it managed to find among the data. You can see this searching process in the example below.
Example
In the following example, we use different names and e-mails as an example of the dataset. The lines that start with > represent the user input. Note that these symbols are not part of the input.
Enter the number of people:
> 6
Enter all people:
> Dwight Joseph [email protected]
> Rene Webb [email protected]
> Katie Jacobs
> Erick Harrington [email protected]
> Myrtle Medina
> Erick Burgess
Enter the number of search queries:
> 3
Enter data to search people:
> ERICK
Found people:
Erick Harrington [email protected]
Erick Burgess
Enter data to search people:
> unknown
No matching people found.
Enter data to search people:
Found people:
Rene Webb [email protected]