카타 8급 Remove First and Last Character

1 C[ | ]

char* remove_char(char* dst, const char* src) {
  strcpy(dst, src+1);
  dst[strlen(dst)-1] = '\0';
  return dst;
}
char* remove_char(char* dst, const char* src) {
  int len = strlen(src);
  for(int i=0; i<len-2; i++) dst[i]=src[i+1];
  dst[len-2] = '\0';
  return dst;
}
char *remove_char(char* dst, const char* src) {
  src ++;
  strncpy(dst, src, strlen(src)-1);
  dst[strlen(src)-1] = '\0';
  return dst;
}
char* remove_char(char* dst, const char* src) {
  char *p = dst;
  src++;
  while(*src) *p++ = *src++;
  p[-1] = 0;
  return dst;
}
char* remove_char(char* dst, const char* src) {
  char *p = dst;
  src++;
  while(*src) *dst++ = *src++;
  dst[-1] = 0;
  return p;
}
char* remove_char(char* dst, const char* src) {
  sprintf(dst, "%.*s", strlen(src)-2, src+1);
  return dst;
}

2 C++[ | ]

#include <string>
using namespace std; 
string sliceString (string str ) {
  return str.substr(1,str.size()-2); 
}
#include <string>
using namespace std; 
string sliceString (string str ) {
  return str.substr(1,str.length()-2); 
}
#include <string>
using namespace std; 
string sliceString (string str ) {
  return string(str.begin()+1,str.end()-1);
}

3 PHP[ | ]

function remove_char(string $s): string {
  return substr($s,1,-1);
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}