카타 8급 Remove String Spaces

Jmnote bot (토론 | 기여)님의 2019년 2월 3일 (일) 04:03 판 (봇: 자동으로 텍스트 교체 (-분류:PHP +))

1 개요

카타 8급 C
# 🔗 문제 풀이

틀:카타 8급-34

2 C++

std::string no_space(std::string x)
{
  x.erase(std::remove(x.begin(), x.end(), ' '), x.end());
  return x;
}
std::string no_space(std::string x)
{    
    std::string temp="";
    for(int i = 0;i<x.size();i++){
      if(x[i]!=' ')
        temp+=x[i];
    }
    return temp;
}

3 PHP

function no_space(string $s): string {
  return str_replace(' ','',$s);
}
function no_space(string $s): string {
  return preg_replace("/\s/", "", $s);
}

4 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}