카타 8급 Squash the bugs

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:47 판 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

C[ | ]

C
Copy
#include <stddef.h>
#include <ctype.h>
size_t find_longest(const char *words) {
  size_t length = 0, max_length = 0;
  const char *pchar = words;
  char c;
  do {
    c = *pchar++;
    if (isspace(c) || c == 0) {
      if (length > max_length) max_length = length;
      length = 0;
    } else {
      length++;
    }
  } while (c);
  return max_length;
}
C
Copy
#include <stddef.h>
#include <ctype.h>
size_t find_longest(const char *words) {
  size_t length = 0, max_length = 0;
  const char *pchar = words;
  char c;
  while ((c = *pchar++)) {
    if (isspace(c)) {
      if (length > max_length)  max_length = length;
      length = 0;
    } else {
      length++;
    }
  }
  if (length > max_length) max_length = length;
  return max_length;
}
C
Copy
#include <stddef.h>
#include <ctype.h>
size_t find_longest(const char *words) {
  size_t length = 0, max_length = 0;
  const char *pchar = words;
  char c;
  while ((c = *pchar++)) {
    if (isspace(c)) {
      if (length > max_length) max_length = length;
      length = 0;
    } else {
      length++;
    }
  }
  return length > max_length ? length : max_length;
}