카타 7급 Going to the cinema

1 C[ | ]

int movie(int card, int ticket, double perc) {
  int a, b, n = 1;
  while(1) {
    a = ticket * n;
    b = ceil(card + ticket*perc*(1-pow(perc,n))/(1-perc));
    if( a > b ) break;
    n++;
  }
  return n;
}
int movie(int card, int ticket, double perc) {
  int ticketTotal = 0, count = 0;
  float card2 = card, ticket2 = ticket;
  for(; ticketTotal <= ceil(card2); ++count) {
    ticketTotal += ticket;
    ticket2 *= perc;
    card2 += ticket2;
  }
  return count;
}
int movie(int card, int ticket, double perc) {
  int n = 0;
  float priceB = card, priceA = 0, percAcc = 1;
  while (priceA <= (int)priceB + 1) {
    percAcc *= perc;
    priceA += ticket;
    priceB += ticket * percAcc;
    n++;
  }
  return n;
}
int movie(int card, int ticket, double perc) {
  int n=1;
  while(1) {
    if(ceil(card + ticket*perc*((pow(perc,n)-1)/(perc-1))) < ticket*n) return n;
    n++;
  }
}

2 Kotlin[ | ]

3 R[ | ]

movie <- function(card, ticket, perc) {
  n <- 1
  while(TRUE) {
    a <- ticket * n
    b <- ceiling( card + ticket*perc*(1-perc^n) / (1-perc) )
    if( a > b ) break
    n <- n + 1
  }
  n
}
movie <- function(card, ticket, perc) {
  n = 1:10000
  min(which(ceiling(card + ticket * cumsum(perc^n)) < ticket * n))
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}