PROG0548 - Canvascrack

no tags 

From 2001 to 2014 the Belgian television channel Canvas was broadcasting the legendary television quiz De Canvascrack. The show was built around the idea that one participant — the crack — competes against a challenger in a short quiz of five multiple choice questions on various subjects, with three possible answers per question. The questions often contained multiple clues from which the correct answer could be derived, either directly or by elimination. Once per show, a round had a set of five questions around a common theme.

Canvascrack
Snapshot of the legendary television quiz De Canvascrack, where the challenger (left) competes against the crack (right) on a set of multiple choice questions.

In each round, the challenger first answered each of the multiple choice questions aloud. After each answer of his challenger, the crack indicated whether or not he thought his opponent had given the correct answer using a pair of hidden buttons. An evaluation followed after each question round, in which both the correct answers and the assessments of the crack were given. The challenger won a point for each correct answer given and the crack won a point for each correct assessment. The total number of points won in a single round decided if the crack won or lost. The exact way in which this happened in not relevant for this assignment.

Each challenger was seated at a different table. After each win, the crack moved on to the next table to take up against the next challenger. Each successive table was a fixed amount of €25 worth more than the previous table: the first table was worth €25, the second €50, the third €75, and so on. After each table won by the crack, the value of that table was added to his total amount. In addition, after each fifth table won the total amount won by the crack was doubled (after the value of the fifth table won was added to the total amount).

After each table won, the crack could decide to stop and take home the total amount he had won so far. He could also decide to move on to the next table, taking the risk to lose money there. Upon losing a table, the total amount won by the crack was halved and the crack was replaced by the challenger that had just beaten him. After having won twenty tables, a crack was forced to stop and take his total amount home.

Canvascracktafels
Overview of the value of the tables in De Canvascrack.

The table below shows the development of a game where the crack wins 20 tables in succession. It indicates the value of each successive tables (second column), whether or not the total amount is doubled after winning this table (this happens at tables 5, 10, 15 and 20; third column) and the total amount the crack has earned after winning the table (fourth column).

table value double profit
1 €25
€25
2 €50
€75
3 €75
€150
4 €100
€250
5 €125 €750
6 €150
€900
7 €175
€1075
8 €200
€1275
9 €225
€1500
10 €250 €3500
table value double profit
11 €275
€3775
12 €300
€4075
13 €325
€4400
14 €350
€4750
15 €375 €10250
16 €400
€10650
17 €425
€11075
18 €450
€11525
19 €475
€12000
20 €500 €25000

A crack that managed to win 20 tables could call himself Supercrack and received the first prize of €25000. Only seven participants accomplished this: Jan Van den Nest (2002), Jimmy Geeraerts (2005), Jan Bosmans (2006), Joris Alen (2007), John Christoffels (2008), Erik Meersschaert (2009) and Geert Tanghe (2014).

Input

In this assignment you have to simulate the game play of De Canvascrack. For each table played, you have to give the total amount won so far by the crack. Instead of assigning each successive table of an additional value of €25 and doubling the total amount after every fifth table won, we provide other values in the input. We also give up the limitation that the crack is forced to stop after having won 20 tables.

There are four lines of input that respectively contain the following information:

  • the total number of tables $n \in \mathbb{N}$ that has been played by the crack
  • the fixed amount $e \in \mathbb{N}$ that every next table is worth more in comparison to the previous table (this is also the value of the first table)
  • the number of tables won $w \in \mathbb{N}$ after which the total amount is doubled
  • a string lost or stopped that indicates whether the crack has lost the last table played, or whether he has won the last table and stopped after that win (either because he chose to do so, or because he had won the maximal number of tables allowed)

Note that the input of the first example below corresponds to the game play in the table shown in the introduction of this assignment.

Output

The output should display a simulation of the game play as defined by the data from the input. One line of output must be generated for each table played, indicating the total amount won so far by the crack. Each table won where the total amount is doubled must be marked with the extra text snippet (x2). In case the last table is lost and halving the total amount gives a half euro, only the integer part of the total amount must be displayed. Take a look at the examples given below to see how the output should be formatted.

Example

Input:

20
25
5
stopped

Output:

table #1: €25
table #2: €75
table #3: €150
table #4: €250
table #5 (x2): €750
table #6: €900
table #7: €1075
table #8: €1275
table #9: €1500
table #10 (x2): €3500
table #11: €3775
table #12: €4075
table #13: €4400
table #14: €4750
table #15 (x2): €10250
table #16: €10650
table #17: €11075
table #18: €11525
table #19: €12000
table #20 (x2): €25000

Example

Input:

9
70
3
lost

Output:

table #1: €70
table #2: €210
table #3 (x2): €840
table #4: €1120
table #5: €1470
table #6 (x2): €3780
table #7: €4270
table #8: €4830
table #9: €2415

Van 2001 tot en met 2014 zond Canvas de legendarische televisiequiz De Canvascrack uit. In deze quiz nam een persoon — de crack — het op tegen een uitdager in een korte quiz van een aantal meerkeuzevragen over allerlei onderwerpen, telkens met drie mogelijke antwoorden. Dikwijls bevatten de vragen meerdere tips waaruit het goede antwoord kon afgeleid worden, of waardoor eliminatie kon toegepast worden. Eén keer per aflevering was er ook een ronde met een welbepaald thema dat als rode draad doorheen de vragen liep.

Canvascrack
Fragment uit de legendarische televisiequiz De Canvascrack waarin een uitdager (links) het opneemt tegen de crack (rechts).

Per ronde beantwoordde de uitdager eerst elke vraag hardop. Na elk antwoord van zijn tegenstrever gaf de crack — onzichtbaar voor de uitdager — aan of hij dacht dat het antwoord van de uitdager al dan niet juist was. Na elke vragenronde volgde een evaluatie waarin de juiste antwoorden op de vragen en de beoordeling van de crack bekendgemaakt werden. Voor elk juist antwoord kreeg de uitdager een punt en voor elke juiste beoordeling kreeg de crack een punt. Op basis van het puntentotaal voor een ronde werd dan beslist of de ronde gewonnen werd door de crack of zijn uitdager. De exacte manier waarop dit gebeurde is niet relevant voor deze opgave.

De uitdagers zaten elk aan een afzonderlijke tafel. Bij winst schoof de crack telkens op naar een volgende tafel om daar een nieuwe uitdager te bekampen. Elke volgende tafel was voor de crack een vast bedrag van €25 meer waard dan de vorige tafel: de eerste tafel was €25 waard, de tweede €50, de derde €75 enzoverder. Na elke tafel die de crack gewonnen had, werd de waarde van de gewonnen tafel toegevoegd aan zijn totaal gewonnen bedrag. Na elke vijfde gewonnen tafel werd het gewonnen bedrag van de crack bovendien ook nog eens verdubbeld (nadat eerst de waarde van de vijfde tafel bij het gewonnen bedrag werd opgeteld).

Na elke gewonnen tafel mocht de crack beslissen om te stoppen en het tot dan toe gewonnen bedrag mee naar huis te nemen. Hij kon ook beslissen om verder te gaan naar de volgende tafel, met het risico om daar geld te verliezen. Bij verlies van een tafel werd het tot dan toe gewonnen bedrag van de crack immers gehalveerd, moest de crack het spel verlaten en werd hij als crack vervangen door de uitdager die tegen hem gewonnen had. Een crack kon maximaal twintig tafels winnen, en was na de twintigste gewonnen tafel verplicht om te stoppen en zijn totaalbedrag mee naar huis te nemen.

Canvascracktafels
Overzicht van de waarde van de tafels in De Canvascrack.

Onderstaande tabel toont het verloop van het spel indien de crack twintig opeenvolgende tafels wint. Daarbij wordt voor elke opeenvolgende tafel de waarde van de tafel aangegeven (tweede kolom), of het gewonnen bedrag zal verdubbeld worden bij winst van de tafel (dit gebeurt bij tafels 5, 10, 15 en 20; derde kolom) en wat het bedrag is die de crack tot dan toe heeft verzameld nadat hij de tafel heeft gewonnen (vierde kolom).

tafel waarde verdubbel winst
1 €25
€25
2 €50
€75
3 €75
€150
4 €100
€250
5 €125 €750
6 €150
€900
7 €175
€1075
8 €200
€1275
9 €225
€1500
10 €250 €3500
tafel waarde verdubbel winst
11 €275
€3775
12 €300
€4075
13 €325
€4400
14 €350
€4750
15 €375 €10250
16 €400
€10650
17 €425
€11075
18 €450
€11525
19 €475
€12000
20 €500 €25000

Wie er in slaagde 20 tafels te winnen mocht zich Supercrack noemen en ontving de hoofdprijs van €25000. Dit is slechts zeven deelnemers gelukt: Jan Van den Nest (2002), Jimmy Geeraerts (2005), Jan Bosmans (2006), Joris Alen (2007), John Christoffels (2008), Erik Meersschaert (2009) en Geert Tanghe (2014).

Invoer

Bij deze opgave moet je het spelverloop van De Canvascrack simuleren, waarbij je na elke gespeelde tafel aangeeft hoeveel de crack tot dan toe gewonnen heeft. In plaats van elke opeenvolgende tafel een meerwaarde van €25 te geven en het gewonnen bedrag na elke vijfde tafel te verdubbelen, geven we via de gegevens uit de invoer eventueel andere waarden op. We laten ook de beperking varen dat de crack maximaal 20 tafels mag spelen.

Er zijn vier regels invoer, die respectievelijk de volgende gegevens bevatten:

  • het totaal aantal tafels $n \in \mathbb{N}$ waaraan de crack gespeeld heeft
  • het vaste bedrag $e \in \mathbb{N}$ dat elke volgende tafel meer waard is dan de vorige tafel (dit is meteen ook de waarde van de eerste tafel)
  • het aantal gewonnen tafels $w \in \mathbb{N}$ waarna het tot dan toe gewonnen bedrag telkens verdubbeld wordt
  • een string verloren of gestopt die aangeeft of de crack de laatst gespeelde tafel verloren heeft, dan wel dat hij die tafel gewonnen heeft en daarna gestopt is (hetzij uit eigen beweging of omdat hij het maximaal toegelaten aan tafels gespeeld heeft)

De invoer van het eerste voorbeeld dat hieronder gegeven wordt, komt bijvoorbeeld overeen met het spelverloop dat wordt weergegeven in de tabel uit de inleiding van deze opgave.

Uitvoer

De uitvoer moet een simulatie weergeven van het spelverloop dat omschreven wordt door de gegevens uit de invoer, waarbij voor elke tafel wordt aangegeven wat het bedrag is dat de crack tot dan toe gewonnen heeft na het spelen van de tafel. Elke gewonnen tafel waarbij het bedrag wordt verdubbeld, moet aangeduid worden met de extra tekst (x2). Indien de laatste tafel verloren wordt, en er na halvering een bedrag zou gewonnen worden met een halve euro, dan moet enkel het geheel gedeelte van dat bedrag uitgeschreven worden. Leid het exacte formaat van de uitvoer af uit onderstaande voorbeelden.

Voorbeeld

Invoer:

20
25
5
gestopt

Uitvoer:

tafel #1: €25
tafel #2: €75
tafel #3: €150
tafel #4: €250
tafel #5 (x2): €750
tafel #6: €900
tafel #7: €1075
tafel #8: €1275
tafel #9: €1500
tafel #10 (x2): €3500
tafel #11: €3775
tafel #12: €4075
tafel #13: €4400
tafel #14: €4750
tafel #15 (x2): €10250
tafel #16: €10650
tafel #17: €11075
tafel #18: €11525
tafel #19: €12000
tafel #20 (x2): €25000

Voorbeeld

Invoer:

9
70
3
verloren

Uitvoer:

tafel #1: €70
tafel #2: €210
tafel #3 (x2): €840
tafel #4: €1120
tafel #5: €1470
tafel #6 (x2): €3780
tafel #7: €4270
tafel #8: €4830
tafel #9: €2415


Added by:Peter Dawyndt
Date:2015-09-04
Time limit:10s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:PY_NBC