이 문제를 해결하는 기본적인 아이디어는 해당 세그먼트의 60 번째 문자 앞의 문자열 세그먼트에서 마지막 공간을 추적하는 것입니다. 이 숙제이기 때문에
, 난 당신이 코드를 마련 할 것이다, 그러나 여기에 위의 제안의 일부 거친 의사 코드입니다 :
- current_position = start of the string
- WHILE current_position NOT past the end of the string
- LOOP 1...60 from the current_position (also don't go past the end of the string)
- IF the character at current_position is a space, set the space_position to this position
- Replace the character (the space) at the space_position with a newline
- Set the current_position to the next character after the space_position
- If you're printing the string rather than inserting newline characters into it, you would print any remaining part of the string here.
또한 사건을 고려하는 것이 좋습니다는 어디 돈 한 블록에 60 자의 공백이 없습니다.
"둘러보기"란 적절한 위치에'\ n'을 삽입하는 것을 의미합니까? – Mysticial
예. 그래서 폭 60과 공간 뒤에 감싸 야합니다. – user1087935
일반적인 숙제 문제와 비슷하게 들릴 수 있습니다. – AusCBloke