Mathematical and Physical Journal
for High Schools
Issued by the MATFUND Foundation
Already signed up?
New to KöMaL?

Problem I. 249. (October 2010)

I. 249. A regular expression is a pattern that can match a set of strings (see e.g. http://en.wikipedia.org/wiki/Regular_expression). They are suitable, for example, to check the structure of certain texts (e.g. email addresses, URLs).

The following tasks from a) to h) should be solved by giving a suitable regular expression. If there is more than one solution, your aim is to choose the regular expression consisting of the least number of characters, if possible.

You should use the following files (each line of them is correct):

-- kartya.txt: successive lines of the file contain the French playing cards in a format suit, space, rank.\ For example: hearts ace, diamond king, spades 10, clubs jack.

-- email.txt: lines of the file contain an email address. \ For example: headmaster@school.hu.

-- telefon.txt: lines of the file contain a telephone number. \ For example: (30)555-55-55, or (46)555-555.

-- rendszam.txt: lines of the file contain registration identifiers from number plates.\ For example: KUTYA-1, PAPA-05, ABC-123.

You should display all lines of the appropriate files that satisfy the following constraints:

a) the registration identifier contains ,,A'' and ,,3'';

b) contain a registration number of the form 3 letters, hyphen, 3 digits;

c) contain a red suit (hearts or diamond);

d) contain a playing card with a number;

e) contain a mobile phone number (possible district numbers are 20, 30 or 70);

f) do not contain a mobile phone number;

g) contain only the lowercase letters of the English alphabet, and possibly ,,@'' (at) and ,,.'' (full stop), further, they end in ,,.hu'';

h) email addresses of the form ,,firstname.lastname@...'' where the last name is ,,kovacs''.

The above tasks are not in order of increasing difficulty. Your solution will be checked by the program egrep, freely downloadable under Windows and Linux.

The following simple example shows how to use egrep:

egrep "[0-9]" kodok.txt

for example finds all lines of the file kodok.txt that contain at least one digit.

You should submit a file i249.txt, containing your solutions to the above tasks from a) to h), further, the name of the operating system and the actual version number of the program egrep used for testing.

(10 pont)

Deadline expired on November 10, 2010.


Sorry, the solution is available only in Hungarian. Google translation

A megoldók kihasználhatták, hogy az adott állományok a megadott szerkezetű adatokat tartalmazzák, így erre építve sokszor nagyon tömör megoldásokat adtak.

Minden feladat esetén 1 pontot ért a helyes megoldás. A feladat szövege szerint a minél tömörebb megoldásra kellett törekedni. Ezt a szempontot a következőképpen vettük figyelembe az értékelésnél. A jó megoldásoknál az kifejezés karakterhosszát, a hibásaknál az adott részfeladatnál előforduló legnagyobb karakterhosszt vettük alapul és ezeket az értékeket összeadtuk. A legrövidebb megoldást adó és a nála összességében 20 karakternél nem hosszabb megoldások 2, a hosszabb, de 50 karakteren belüli megoldások 1 pontot értek.

Mintamegoldás:


Statistics:

8 students sent a solution.
10 points:Szabó 928 Attila.
9 points:Kalló Kristóf.
8 points:2 students.
7 points:1 student.
6 points:1 student.
5 points:1 student.
0 point:1 student.

Problems in Information Technology of KöMaL, October 2010