카타 7급 Printer Errors

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:41 판 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 C[ | ]

2 Kotlin[ | ]

fun printerError(s: String): String {
    val total: Int = s.length
    val part: Int = total - "[a-m]".toRegex().findAll(s).count()
    return part.toString() + "/" + total.toString()
}
fun printerError(s: String) = "${s.count { it !in 'a'..'m' }}/${s.length}"
fun printerError(s: String): String {
  val wrong = s.count { it.toInt() > 'm'.toInt() }
  return "$wrong/${s.length}"
}
fun printerError(s: String): String {
    return "${s.count{it > 'm'}}/${s.length}"
}

3 R[ | ]

printerError <- function(s) {
  total = nchar(s)
  part = total - sum(unlist(strsplit(s,"")) %in% letters[1:13])
  paste0(part,'/',total)
}
printerError <- function(s) {
  sprintf("%d/%d", nchar(gsub("[a-m]", "", s)), nchar(s))
}
printerError <- function(s) {
  ns <- nchar(s)
  errors <- nchar(gsub("[a-m]", "", s))
  paste(errors, "/", ns, sep = "")
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}