"카타 7급 Going to the cinema"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(다른 사용자 한 명의 중간 판 하나는 보이지 않습니다)
1번째 줄: 1번째 줄:
==C==
==C==
{{카타|7급|C|3}}
{{카타|7급|C|3}}
<source lang='c'>
<syntaxhighlight lang='c'>
</source>
int movie(int card, int ticket, double perc) {
<source lang='c'>
  int a, b, n = 1;
</source>
  while(1) {
<source lang='c'>
    a = ticket * n;
</source>
    b = ceil(card + ticket*perc*(1-pow(perc,n))/(1-perc));
    if( a > b ) break;
    n++;
  }
  return n;
}
</syntaxhighlight>
<syntaxhighlight lang='c'>
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;
}
</syntaxhighlight>
<syntaxhighlight lang='c'>
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;
}
</syntaxhighlight>
<syntaxhighlight lang='c'>
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++;
  }
}
</syntaxhighlight>


==Kotlin==
==Kotlin==
{{카타|7급|Kotlin|1}}
{{카타|7급|Kotlin|1}}
<source lang='kotlin'>
<syntaxhighlight lang='kotlin'>
</source>
</syntaxhighlight>
<source lang='kotlin'>
<syntaxhighlight lang='kotlin'>
</source>
</syntaxhighlight>
<source lang='kotlin'>
<syntaxhighlight lang='kotlin'>
</source>
</syntaxhighlight>


==R==
==R==
{{카타|7급|R|2}}
{{카타|7급|R|2}}
<source lang='r'>
<syntaxhighlight lang='r'>
movie <- function(card, ticket, perc) {
movie <- function(card, ticket, perc) {
   n <- 1
   n <- 1
30번째 줄: 70번째 줄:
   n
   n
}
}
</source>
</syntaxhighlight>
<source lang='r'>
<syntaxhighlight lang='r'>
movie <- function(card, ticket, perc) {
movie <- function(card, ticket, perc) {
   n = 1:10000
   n = 1:10000
   min(which(ceiling(card + ticket * cumsum(perc^n)) < ticket * n))
   min(which(ceiling(card + ticket * cumsum(perc^n)) < ticket * n))
}
}
</source>
</syntaxhighlight>

2020년 11월 2일 (월) 02:41 기준 최신판

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 }}