Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 CCC 2000 Stage1: S1J3: Slot Machines
Index -> Contests
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tony




PostPosted: Sat Feb 08, 2003 2:29 pm   Post subject: CCC 2000 Stage1: S1J3: Slot Machines

Solution to 1st Senior program (3rd on Junior level) writen in C++.
--------------------------------------------------------------------------------

Martha takes a jar of quarters to the casino with the intention of becoming rich. She plays three machines in turn. Unknown to her, the machines are entirely predictable. Each play costs one quarter. The first machine pays 30 quarters every 35th time it is played; the second machine pays 60 quarters every 100th time it is played; the third pays 9 quarters every 10th time it is played.

Your program should take as input the number of quarters in Martha's jar (there will be at least one and fewer than 1000), and the number of times each machine has been played since it last paid.

Your program should output the number of times Martha plays until she goes broke.

Input/output is not from/to files for this question. Keyboard input and screen output is expected.



Sample Session. User input is in italics
How many quarters does Martha have in the jar?
48

How many times has the first machine been played since paying out?
3

How many times has the second machine been played since paying out?
10

How many times has the third machine been played since paying out?
4

Martha plays 66 times before going broke.
--------------------------------------------------------------------------------

Some Notes:

The solution is quite simple. You just run a loop simulating the casino where 3 machines are played in turn (1st - 2nd - 3rd - back to 1st). You count how much each machine is played (remember that all machines were played by other people before, so don't start from 0Wink)

You should also keep in mind that she CANT borrow some quaters to compleat the turn... such as if she has 1 quater left, she plays 1st machine, and not 2nd and 3rd unless 1st machine pays on that turn.

In my solution the final output is the counter of plays + jar because if she gous into negative coin amount those plays shouldn't count.

See file attached for solution.



source.cpp
 Description:
updated source file for 2000 S1J3 problem

Download
 Filename:  source.cpp
 Filesize:  952 Bytes
 Downloaded:  1023 Time(s)

Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: Mon Feb 24, 2003 9:31 am   Post subject: turing version

i was studying some of thess expame question and i tested my self by making a turing version of this progame with out looking at the solution. i atcuched my slotion. i lefted out erro cheking the input for the user input in this one.

hey tony tell me what you think, i cheked it with the data form sample run and it wroked so i think it is right.



ccc.t
 Description:

Download
 Filename:  ccc.t
 Filesize:  774 Bytes
 Downloaded:  1142 Time(s)

Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Display posts from previous:   
   Index -> Contests
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: