jdeokkim   2년 전

제출 결과: "틀렸습니다"

()             => yes
[]             => yes
()[]           => yes
..             => yes
x.             => yes
([])           => yes 
[()]           => yes
 .             => yes
.x             => yes
(              => no
)              => no
))             => no
[              => no
]              => no
(()            => no
((((           => no
(])            => no
([)]           => no
([)])          => no
[()())         => no
[(()]          => no
[]][           => no
()][           => no
()))           => no
([)].          => no
(]).           => no
x(()           => no
[))))]         => no
[(()]).        => no
[()()).        => no
[(()[])[()]](. => no
(])            => no
][.            => no
.

bupjae   2년 전

종료 조건이 불완전합니다.

   

fgets 함수는 줄바꿈 문자를 만나면 줄바꿈 문자도 buffer 에 넣습니다.

즉, 데이터의 종료를 나타내는 문자열은 ".\n" 이 됩니다.

jdeokkim   2년 전

bupjae님이 말씀하신 대로 문자열 맨 뒤의 개행 문자를 제거하는 코드를 넣어 문제를 해결하였습니다.

쉽게 설명해주셔서 감사합니다!

buffer[strcspn(buffer, "\r\n")] = 0;

jdeokkim   2년 전

다른 분들에게도 도움이 될 수 있을 것 같아 관련 내용도 같이 첨부합니다.

char *fgets( char *restrict str, int count, FILE *restrict stream );

Reads at most `count - 1` characters from the given file stream and stores them in the character array pointed to by `str`. Parsing stops if a newline character is found, in which case `str` will contain that newline character, or if end-of-file occurs. If bytes are read and no errors occur, writes a null character at the position immediately after the last character written to `str`.

※ 출처: https://en.cppreference.com/w/c/io/fgets

댓글을 작성하려면 로그인해야 합니다.