# Problem I. 397. (March 2016)

**I. 397.** **(É.)** A chess tournament with 32 participants is organized as follows. In the first round, the organizers create some groups, then they play a round-robin tournament within each group (that is, everybody plays against any other player in their group). Initially each contestant has 100 points. The winner of each game gets 5% of the points of the opponent rounded up to the nearest integer. The points of the defeated player are not changed. In case of a tie, the game is repeated.

The results after the first round together with the Hungarian players' names are found in the text file `sakk.txt` (downloadable from our web page). Each line of the file corresponds to one player and contains the following data: player's points, family name, given name(s)—separated by a space. The file does not contain characters with diacritical marks, nor unnecessary lines or spaces, and no name prefixes (such as Dr or Mr). A short sample of the file is displayed below:

In the second round, they play a single-elimination tournament (consisting of several turns), which is explained below. The players are sorted according to descending points, and the first player plays with the last one, the second player with the second last, and so on. Players having the same number of points are sorted into alphabetical order. Players in the pairs obtained this way play one game against each other in the first turn. The winners get extra points as described above, while the defeated players are out of the tournament. Then the organizers again sort the players. In the second turn the remaining players again play one game against each other. This process is repeated until the last game.

Create your program `i397` to solve the following tasks. Before displaying your solution, the actual problem number should appear on the screen such as ,,`Task #3`''. Instead of displaying a player's given name, only its first character should appear followed by a dot. When a Hungarian name begins with a digraph, both characters should be displayed.

1. Import and store data from the file `sakk.txt`.

2. Display the players' names on the screen in the original order by using the following format:

3. Simulate the games between pairs of players in the second round so that the chance of winning should be proportional to the current points of the player. More precisely, you should do the following. Suppose the two players have points \(\displaystyle A\) and \(\displaystyle B\). Generate a random integer between 1 and \(\displaystyle A+B\) inclusive. The first player is the winner, if the random integer is between \(\displaystyle 1\) and \(\displaystyle A\); the second player is the winner, if the random integer is between \(\displaystyle A+1\) and \(\displaystyle A+B\). Your Boolean function `ElsoNyer` should yield ``true'' if the first player wins, and ``false'' if the second wins. The input of this function is the pair of points \(\displaystyle (A,B)\).

4. Play the first turn of the second round by using the previous Boolean function. Display the players' data at the end of the turn. Each line should contain a pair of players by using the format given in Task 2 above. Lines should be separated by the string (`---`).

5. Determine who scored the maximum points against whom in the first turn of the second round. You should display this in a sentence such as ,,`Kiss-Kerekes E. (396) scored the maximum points (18) against Kovacs A. Gy. (345)`''.

6. Simulate also the second turn of the second round. Results after the 8 games should be written in the file `kor2.txt` together with the pairing described in Task 4.

7. By using an abbreviated name format and separated by a comma, list those players who are eliminated in the second turn but still scored more points than the player with minimum points qualified for the third turn.

8. Simulate the remaining turns and display data for the two players in the final, and the winner of the tournament.

The source code and a short documentation of your program—containing a brief description of your solution, and the name of the developer environment to compile your code—should be submitted in a compressed file `i397.zip`.

Downloadable file: sakk.txt

(10 pont)

**Deadline expired on April 11, 2016.**

### Statistics:

6 students sent a solution. 10 points: Nagy Ábel, Szakali Benedek. 9 points: Olexó Gergely, Rittgasszer Ákos. 8 points: 1 student. 7 points: 1 student.

Problems in Information Technology of KöMaL, March 2016