"카타 8급 Remove String Spaces"의 두 판 사이의 차이

47번째 줄: 47번째 줄:
     return temp;
     return temp;
}
}
</source>
==Kotlin==
{{카타|8급|Kotlin|2}}
<source lang='kotlin'>
</source>
<source lang='kotlin'>
</source>
</source>



2019년 4월 15일 (월) 01:43 판

1 C

#include <stdlib.h>
char *no_space(char *strin) {
  int len = strlen(strin);
  char *res = malloc(len);
  int offset = 0;
  for(int i=0; i<len; i++) {
    while(strin[i+offset]==' ') offset++;
    res[i] = strin[i+offset];
  }
  return res;
}
#include <stdlib.h>
char *no_space(char *strin) {
  char *res = malloc(strlen(strin)+1);
  char *p = res;  
  while(*strin) {
    if(*strin != ' ') *p++ = *strin;
    strin++;
  }
  *p='\0';
  return res;
}

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 Kotlin

4 PHP

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

5 같이 보기