Peter and Casino

 

Hotel Royal Gardenia has arranged for an elite business party for the lead industrialists and celebrities of the City. Followed by a dinner buffet, the Event coordinators planned for some casino game events for the high-toned crowd. Peter was a visitor at the party and he takes some number of rubles to the casino with the intention of becoming rich. He plays three machines in turn. Unknown to him, the machines are entirely predictable. Each play costs one ruble. The first machine pays 20 rubles every 25th time it is played; the second machine pays 80 rubles every 120th time it is played; the third pays 8 rubles every 12th time it is played.
Given the number of rubles with Peter initially (there will be at least one and fewer than 1000), and the number of times each machine has been played since it last paid, write a program that calculates the number of times Peter plays until he goes broke.

Input Format:
First line of the input is an integer that corresponds to the number of rubles with Peter initially.
Next 3 lines of the input is an integer that corresponds to the number of times each machine has been played since it last paid.

Output Format:
Output a single line that gives the number of times Peter plays until he goes broke.
Refer sample input and output for formatting specifications.

Sample Input 1:
48
3
12
4

Sample Output 1:
Peter plays 56 times before going broke

Sample Input 2:
35
10
30
9

Sample Output 2:
Peter plays 71 times before going broke



#include<stdio.h>
int main()
{
    int money,first,second,third,one=0,two=0,three=0,n1=0,n2=0,n3=0;
    scanf("%d",&money);
    scanf("%d",&first);
    scanf("%d",&second);
    scanf("%d",&third);
    while(money!=0)
    {
        one++;
        if(n1==0 && one==25-first)
        {
            money+=20;
            money--;
            n1=25-first+25;
        }
        else if(one==n1)
        {
            money+=20;
            money--;
            n1+=25;
        }
        else{
            money--;
            if(money==0){
                break;
            }
        }two++;
        if (n2==0 && two==120-second)
        {
            money+=80;
            money--;
            n2=120-second+120;
        }
        else if(two==n2)
        {
            money+=80;
            money--;
            n2+=120;
        }
        else{
            money--;
            if(money==0){
                break;
            }
        }three++;
        if (n3==0 && three==12-third)
        {
            money+=8;
            money--;
            n3=12-third+12;
        }
        else if(three==n3)
        {
            money+=8;
            money--;
            n3+=12;
        }
        else{
            money--;
            if(money==0){
                break;
            }
        }
        
    }
    printf("Peter plays %d times before going broke",(one+two+three));
    
}

Comments

Popular posts from this blog

Lucy at the Film Festival