pwgm11jan   1년 전

예제를 입력했더니 이렇게 나옵니다...
입력 :

1
RDD
4
[1,2,3,4]

출력 :

[2,123818

맞는 거 같은데...

jtw7913   1년 전

72번줄에 cout << ']\n'; 가 아니라 cout << "]\n";을 사용하시거나 cout << ']' << '\n';을 사용하셔야 합니다. (고치면 AC입니다.)

']\n'은 multi-character으로 불리는데 이는 implementation-defined입니다. (cppreference - Character literal)

백준에서 사용하는 C++컴파일러는 gcc이므로 내용을 확인해보면 (gcc - Implementation-defined behavior)

The compiler evaluates a multi-character character constant a character at a time, 
shifting the previous value left by the number of bits per target character, 
and then or-ing in the bit-pattern of the new character truncated to the width of a target character. 
The final bit-pattern is given type int, and is therefore signed, regardless of whether single characters are signed or not. 
If there are more characters in the constant than would fit in the target int 
the compiler issues a warning, and the excess leading characters are ignored

로 나와있으며 문자열이 아니라 int형인 결과가 나와 작성자님의 출력결과 처럼 [2,123818이 나오는것 입니다.

참고로 gcc로 컴파일하면 컴파일 경고로 warning: multi-character character constant [-Wmultichar] 을 띄워줍니다.

pwgm11jan   1년 전

앗! 감사합니다!!

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