카타 7급 Exes and Ohs

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