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.
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
48
3
12
4
Sample Output 1:
Peter plays 56 times before going broke
Solution:
#include<stdio.h>
int main()
{
int r,a,b,c,count=0;
scanf("%d%d%d%d",&r,&a,&b,&c);
while(r>0)
{
if(a==25)
{
r=r+20;
}
r--;
count++;
if(r==0)
break;
if(b==120)
{
r=r+80;
}
r--;
count++;
if(r==0)
break;
if(c==12)
{
r=r+8;
}
r--;
count++;
if(r==0)
break;
a++,b++,c++;
}
printf("Peter plays %d times before going broke",count);
return 0;
}
But the following input is not working
ReplyDelete35
10
30
9
Answer 71 but this code is not satisfy this test case.
just put increment term above if condition
DeleteI can't understand this
Deletebro i placed a++,b++,c++ below the while but still notworking for other test case please help,THank you
Deletesame doubt for me also
Deletehave u got that solution
This comment has been removed by the author.
Delete#include
Deleteint main(){
int r,m1,m2,m3;
scanf("%d %d %d %d",&r,&m1,&m2,&m3);
int c1=0,c2=0,c3=0;
int n1=0,n2=0,n3=0;
int t1=25-m1;
int t2=120-m2;
int t3=12-m3;
while(r>0){
c1++;
if(n1==0 && c1==t1){
r+=20;
r--;
n1=t1+25;
}
else if(c1==n1){
n1+=25;
r+=20;
r--;
}
else{
r--;
if(r==0)
break;
}
c2++;
if(n2==0 && c2==t2){
r+=80;
r--;
n2=t2+120;
}
else if(c2==n2){
n2+=120;
r+=80;
r--;
}
else{
r--;
if(r==0)
break;
}
c3++;
if(c3==t3 && n3==0){
r+=8;
r--;
n3=t3+12;
}
else if(c3==n3){
n3+=12;
r+=8;
r--;
}
else{
r--;
if(r==0)
break;
}
}
printf("Peter plays %d times before broke",c1+c2+c3);
return 0;
}
Use % function in the if condition
DeleteEx - if(a%25==0)
Since it gives 20 every 25th time
#include
Deleteint main(){
int r,m1,m2,m3; //input variables
scanf("%d %d %d %d",&r,&m1,&m2,&m3);
int c1=0,c2=0,c3=0; //counter for each machine
//number of pays to refund - only required for 0th case
int t1=25-m1; //rolls left after the last state of machine to reach refund
int t2=120-m2;
int t3=12-m3;
int n1=0,n2=0,n3=0; //after 0th case n1 takes over
while(r>0){
c1++; //m1 transaction
if(n1==0/*0th case*/ && c1==t1 /*rolls reached*/){
r+=20; // refund
r--; //for that round
n1=t1+25; /*n1 takes over t1 -> 25 is added to t1 and saved in n1 - this will be the target when
the machine will again give refund*/
}
else if(c1==n1)/* next target reached when refund will be given*/{
n1+=25; // target incremented
r+=20; //refund
r--; // for the round
}
else{ //other cases when he just loses the rubles
r--;
if(r==0) // if the rubles are depleated he goes broke and he cant play any further
break;
}
c2++;
if(n2==0 && c2==t2){
r+=80;
r--;
n2=t2+120;
}
else if(c2==n2){
n2+=120;
r+=80;
r--;
}
else{
r--;
if(r==0)
break;
}
c3++;
if(c3==t3 && n3==0){
r+=8;
r--;
n3=t3+12;
}
else if(c3==n3){
n3+=12;
r+=8;
r--;
}
else{
r--;
if(r==0)
break;
}
}
printf("Peter plays %d times before broke",c1+c2+c3);
return 0;
}
/* Just Documented it so that the code becomes clear for everyone */
does it work for input 35, 10,30,9
Deletethank u for sharing this post Meraki Firewall
ReplyDeleteMeraki Cloud
Wonderful illustrated information. I thank you about that. No doubt it will be very useful for my future projects. Would like to see some other posts on the same subject!
ReplyDeleteMKT Vegas831
Thanks for sharing nice information with us. i like your post and all you share with us is uptodate and quite informative. i would like to bookmark the page so i can come here again to read you. as you have done a wonderful job.
ReplyDeleteXE88 Download FataBet
I am looking for and I love to post a comment that "The content of your post is awesome" Great work! promo judi slot
ReplyDeletePerhaps you have played lots of casino online games. If you don't know famous Indian online casino games or never played these games then you can read about these games here. These games are so interesting and enjoyable to play.
ReplyDeleteExcellent information on your blog, thank you for taking the time to share with us. Amazing insight you have on this, it's nice to find a website that details so much information about different artists.
ReplyDeletelogin joker123
Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place..
ReplyDeletedominoqq online
can u explain me the above code
ReplyDeleteThank you so much for sharing
ReplyDeleteI really appreciate your support on this.
ReplyDeleteLook forward to hearing from you soon.
I’m happy to answer your questions, if you have any.
คาสิโน
เล่นบาคาร่า
เครดิตฟรี
แจกเครดิตฟรี ฝากถอนง่าย
Many thanks for your kind invitation. I’ll join you.
ReplyDeleteWould you like to play cards?
Come to the party with me, please.
See you soon...
เครดิตฟรี
คาสิโนออนไลน์
เล่นบาคาร่า
คาสิโนออนไลน์
#include
ReplyDeleteint main(){
int r,m1,m2,m3; //input variables
scanf("%d %d %d %d",&r,&m1,&m2,&m3);
int c1=0,c2=0,c3=0; //counter for each machine
//number of pays to refund - only required for 0th case
int t1=25-m1; //rolls left after the last state of machine to reach refund
int t2=120-m2;
int t3=12-m3;
int n1=0,n2=0,n3=0; //after 0th case n1 takes over
while(r>0){
c1++; //m1 transaction
if(n1==0/*0th case*/ && c1==t1 /*rolls reached*/){
r+=20; // refund
r--; //for that round
n1=t1+25; /*n1 takes over t1 -> 25 is added to t1 and saved in n1 - this will be the target when
the machine will again give refund*/
}
else if(c1==n1)/* next target reached when refund will be given*/{
n1+=25; // target incremented
r+=20; //refund
r--; // for the round
}
else{ //other cases when he just loses the rubles
r--;
if(r==0) // if the rubles are depleated he goes broke and he cant play any further
break;
}
c2++;
if(n2==0 && c2==t2){
r+=80;
r--;
n2=t2+120;
}
else if(c2==n2){
n2+=120;
r+=80;
r--;
}
else{
r--;
if(r==0)
break;
}
c3++;
if(c3==t3 && n3==0){
r+=8;
r--;
n3=t3+12;
}
else if(c3==n3){
n3+=12;
r+=8;
r--;
}
else{
r--;
if(r==0)
break;
}
}
printf("Peter plays %d times before broke",c1+c2+c3);
return 0;
}
50
ReplyDelete4
5
50
Wrong answer giving
Will this logic work ?
ReplyDeleteimport java.util.Scanner;
class HelloWorld {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Value rubbles: ");
int rubbles = sc.nextInt();
System.out.print("Value A: ");
int a = sc.nextInt();
System.out.print("Value B: ");
int b = sc.nextInt();
System.out.print("Value C: ");
int c = sc.nextInt();
int turn = 0;
int count = 0;
while(rubbles > 0)
{
if(turn % 3 == 0){
rubbles -= 1;
a += 1;
if(a % 25 == 0)
rubbles += 20;
}
else if(turn % 3 == 1){
rubbles -= 1;
b += 1;
if(b % 120 == 0)
rubbles += 80;
}
else{
rubbles -= 1;
c += 1;
if(c % 12 == 0)
rubbles += 8;
}
turn +=1;
count+=1;
}
System.out.println(count);
}
}
Thank you for providing such a comprehensive look at this subject! Your blog is always a pleasure to read and a fantastic learning experience. Contact live casino login now.
ReplyDelete