만드는 중입니다

아직 만드는 중이라 바뀔 수 있습니다

ReWord-wrap

시간 제한1초메모리 제한1024 MB

요약
주어진 텍스트를 너비 w 이하의 줄로 나누어, 단어를 쪼개지 않고 다시 배치하는 문제입니다.
난이도

쉬움10점 중 3점

유형
문자열, 그리디, 구현
정답자
아직 제출이 없습니다

문제

텍스트 편집기 창의 크기가 바뀌면 단어를 쪼개지 않고 모든 단어가 화면 창에 맞도록 텍스트를 다시 배치해야 하는 경우가 많다. 이를 단어 줄바꿈(word-wrapping)이라고 한다. 주어진 텍스트를 지정한 크기에 맞게 줄바꿈하라.

입력

첫 줄에는 데이터셋의 개수를 나타내는 정수 n이 주어진다. 각 데이터셋은 다음과 같이 구성된다.

  • 줄바꿈할 글자 수를 나타내는 정수 w. 10≤w≤5010 \le w \le 50.
  • 줄바꿈할 텍스트의 줄 수를 나타내는 정수 m. 1≤m≤1001 \le m \le 100.
  • 줄바꿈할 텍스트 m줄.

출력

지정된 글자 수에 맞게 텍스트를 줄바꿈하여 출력하고, 각 데이터셋 뒤에 빈 줄을 하나 출력한다.

예제1

  1. 예제 1

    입력
    2
    40
    4
    Chinua Achebe was born on November 16, 1930 into the Igbo
    African ethnic group in southern Nigeria. He was raised in a
    Christian family, but he was always fascinated by the
    traditional African religion and culture.
    35
    4
    Achebe uses the short story of a hard working man
    in a war torn area with a bright outlook on life to act
    as a model for other Africans affected by
    the Nigerian Civil War.
    
    예상 출력
    Chinua Achebe was born on November 16,
    1930 into the Igbo African ethnic group
    in southern Nigeria. He was raised in a
    Christian family, but he was always
    fascinated by the traditional African
    religion and culture.
    
    Achebe uses the short story of a
    hard working man in a war torn area
    with a bright outlook on life to
    act as a model for other Africans
    affected by the Nigerian Civil War.