"카타 8급 Century From Year"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(다른 사용자 한 명의 중간 판 하나는 보이지 않습니다)
1번째 줄: 1번째 줄:
==C==
==C==
{{카타|8급|C|9}}
{{카타|8급|C|9}}
<source lang='C'>
<syntaxhighlight lang='C'>
int centuryFromYear(int year) {
int centuryFromYear(int year) {
   return (year+99)/100;
   return (year+99)/100;
}
}
</source>
</syntaxhighlight>


==C++==
==C++==
{{카타|8급|C++|8}}
{{카타|8급|C++|8}}
<source lang='cpp'>
<syntaxhighlight lang='cpp'>
int centuryFromYear(int year)  
int centuryFromYear(int year)  
{
{
   return (year+99)/100;
   return (year+99)/100;
}
}
</source>
</syntaxhighlight>


==Go==
==Go==
<source lang='go'>
<syntaxhighlight lang='go'>
package kata
package kata
func century(year int) int {
func century(year int) int {
   return (year+99)/100;
   return (year+99)/100;
}
}
</source>
</syntaxhighlight>


==Kotlin==
==Kotlin==
{{카타|8급|Kotlin|3}}
{{카타|8급|Kotlin|3}}
<source lang='kotlin'>
<syntaxhighlight lang='kotlin'>
</source>
fun century(number: Int): Int {
<source lang='kotlin'>
    return (number+99)/100
</source>
}
</syntaxhighlight>
<syntaxhighlight lang='kotlin'>
fun century(number: Int): Int {
    return ceil(number / 100.0).toInt()
}
</syntaxhighlight>
<syntaxhighlight lang='kotlin'>
fun century(number: Int): Int {
    return ((number - 1) / 100).toInt() + 1
}
</syntaxhighlight>


==R==
==R==
{{카타|8급|R|2}}
{{카타|8급|R|2}}
<source lang='r'>
<syntaxhighlight lang='r'>
century <- function(year) {
century <- function(year) {
   (year+99) %/% 100
   (year+99) %/% 100
}
}
</source>
</syntaxhighlight>

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

1 C[ | ]

C
Copy
int centuryFromYear(int year) {
  return (year+99)/100;
}

2 C++[ | ]

C++
Copy
int centuryFromYear(int year) 
{
  return (year+99)/100;
}

3 Go[ | ]

Go
Copy
package kata
func century(year int) int {
  return (year+99)/100;
}

4 Kotlin[ | ]

Kotlin
Copy
fun century(number: Int): Int {
    return (number+99)/100
}
Kotlin
Copy
fun century(number: Int): Int {
    return ceil(number / 100.0).toInt()
}
Kotlin
Copy
fun century(number: Int): Int {
    return ((number - 1) / 100).toInt() + 1
}

5 R[ | ]

R
Copy
century <- function(year) {
  (year+99) %/% 100
}