"카타 8급 Sentence Smash"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(다른 사용자 한 명의 중간 판 4개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
{{카타 헤더}}
{{카타 8급-4}}
|}
==C==
==C==
{{카타|8급|C|2}}
{{카타|8급|C|2}}
<source lang='c'>
<syntaxhighlight lang='c'>
#include <string.h>
#include <string.h>
char *smash(const char **words, size_t count) {
char *smash(const char **words, size_t count) {
17번째 줄: 12번째 줄:
   return res;
   return res;
}
}
</source>
</syntaxhighlight>
<source lang='c'>
<syntaxhighlight lang='c'>
#include <string.h>
#include <string.h>
char *smash(const char **words, size_t count) {
char *smash(const char **words, size_t count) {
32번째 줄: 27번째 줄:
   return res;
   return res;
}
}
</source>
</syntaxhighlight>
<source lang='c'>
<syntaxhighlight lang='c'>
#include <string.h>
#include <string.h>
char *smash(const char **words, size_t count) {
char *smash(const char **words, size_t count) {
49번째 줄: 44번째 줄:
   return res;
   return res;
}
}
</source>
</syntaxhighlight>


==PHP==
==PHP==
<source lang='php'>
{{카타|8급|PHP|2}}
<syntaxhighlight lang='php'>
function smash(array $words): string {
function smash(array $words): string {
   return implode(' ', $words);
   return implode(' ', $words);
}
}
</source>
</syntaxhighlight>


 
==R==
[[분류:카타 8급 C]]
{{카타|8급|R|1}}
[[분류:카타 8급 PHP]]
<syntaxhighlight lang='r'>
smash <- function(words){
  paste(words, collapse=" ")
}
</syntaxhighlight>

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

1 C[ | ]

#include <string.h>
char *smash(const char **words, size_t count) {
  char *res = malloc(1000);
  res[0] = '\0';
  for(int i=0; i<count; i++) {
    strcat(res, words[i]);
    if(i<count-1) strcat(res, " ");
  }
  return res;
}
#include <string.h>
char *smash(const char **words, size_t count) {
  int len = count;
  for(int i=0; i<count; i++) len += strlen(words[i]);
  char* res;
  res = (char*) malloc(len);
  res[0] = '\0';
  for(int i=0; i<count; i++) {
    strcat(res, words[i]);
    if(i<count-1) strcat(res, " ");
  }
  return res;
}
#include <string.h>
char *smash(const char **words, size_t count) {
  char *res= malloc(1000);
  int idx = 0;
  for(int i=0; i<count; i++) {
    for(int pos=0; words[i][pos]!=0; pos++) {
      res[idx] = words[i][pos]; idx++;
    }
    if(i+1 != count) {
      res[idx] = ' '; idx++;
    }
  }
  res[idx] = 0;
  return res;
}

2 PHP[ | ]

function smash(array $words): string {
  return implode(' ', $words);
}

3 R[ | ]

smash <- function(words){
  paste(words, collapse=" ") 
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}