"카타 7급 Exes and Ohs"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(다른 사용자 한 명의 중간 판 하나는 보이지 않습니다)
1번째 줄: 1번째 줄:
==C==
==C==
{{카타|7급|C|2}}
{{카타|7급|C|2}}
<source lang='c'>
<syntaxhighlight lang='c'>
</source>
#include <stdbool.h>
bool xo (const char* str)
{
  char *p = str;
  int count = 0;
  while(*p) {
    if(*p=='o'||*p=='O') count++;
    else if(*p=='x'||*p=='X') count--;
    *p++;
  }
  return count==0;
}
</syntaxhighlight>


==R==
==R==
{{카타|7급|R|1}}
{{카타|7급|R|1}}
<source lang='r'>
<syntaxhighlight lang='r'>
xo <- function(s){
xo <- function(s){
   v <- unlist(strsplit(tolower(s),""))
   v <- unlist(strsplit(tolower(s),""))
   sum(v == "o") == sum(v == "x")
   sum(v == "o") == sum(v == "x")
}
}
</source>
</syntaxhighlight>
<source lang='r'>
<syntaxhighlight lang='r'>
xo <- function(s){
xo <- function(s){
   s <- tolower(s)
   s <- tolower(s)
   nchar(gsub("x","",s)) == nchar(gsub("o","",s))
   nchar(gsub("x","",s)) == nchar(gsub("o","",s))
}
}
</source>
</syntaxhighlight>
<source lang='r'>
<syntaxhighlight lang='r'>
xo <- function(s){
xo <- function(s){
   v <- unlist(strsplit(tolower(s), ""))
   v <- unlist(strsplit(tolower(s), ""))
   length(grep("x",v,ignore.case=TRUE)) == length(grep("o",v,ignore.case=TRUE))
   length(grep("x",v,ignore.case=TRUE)) == length(grep("o",v,ignore.case=TRUE))
}
}
</source>
</syntaxhighlight>
<source lang='r'>
<syntaxhighlight lang='r'>
xo <- function(s){
xo <- function(s){
   v = unlist(strsplit(s,""))
   v = unlist(strsplit(s,""))
   sum(v %in% c("x","X")) == sum(v %in% c("o","O"))
   sum(v %in% c("x","X")) == sum(v %in% c("o","O"))
}
}
</source>
</syntaxhighlight>
<source lang='r'>
<syntaxhighlight lang='r'>
xo <- function(s){
xo <- function(s){
   v = unlist(strsplit(s,""))
   v = unlist(strsplit(s,""))
   length(v[v=="x"|v=="X"]) == length(v[v=="o"|v=="O"])
   length(v[v=="x"|v=="X"]) == length(v[v=="o"|v=="O"])
}
}
</source>
</syntaxhighlight>

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

1 C[ | ]

#include <stdbool.h>
bool xo (const char* str)
{
  char *p = str;
  int count = 0;
  while(*p) {
    if(*p=='o'||*p=='O') count++;
    else if(*p=='x'||*p=='X') count--;
    *p++;
  }
  return count==0;
}

2 R[ | ]

xo <- function(s){
  v <- unlist(strsplit(tolower(s),""))
  sum(v == "o") == sum(v == "x")
}
xo <- function(s){
  s <- tolower(s)
  nchar(gsub("x","",s)) == nchar(gsub("o","",s))
}
xo <- function(s){
  v <- unlist(strsplit(tolower(s), ""))
  length(grep("x",v,ignore.case=TRUE)) == length(grep("o",v,ignore.case=TRUE))
}
xo <- function(s){
  v = unlist(strsplit(s,""))
  sum(v %in% c("x","X")) == sum(v %in% c("o","O"))
}
xo <- function(s){
  v = unlist(strsplit(s,""))
  length(v[v=="x"|v=="X"]) == length(v[v=="o"|v=="O"])
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}