Welcome Sign

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

요약
r개의 단어를 너비 c의 각 행에 가운데 정렬로 배치하고, 남는 칸이 홀수일 때 좌우 어느 쪽에 빈칸을 더 둘지 번갈아 정한다.
난이도

쉬움10점 중 3점

유형
구현, 문자열, 시뮬레이션
정답자
아직 제출이 없습니다

문제

Amanda is opening a new bakery in town. She will put up a fancy LED sign to show a grand opening message on the storefront window. The sign has rr rows and cc columns of display units. Each unit can display one letter or be blank.

Amanda has written a message consisting of exactly rr words. She will arrange them onto the LED sign such that each row will display one word from the message in order. Each word must be as centered as possible, which means that if the number of blanks on the left side and right side of the word are ll and rr, then ∣l−r∣|l - r| must be as close to zero as possible. On those rows where ll cannot equal rr, Amanda would like to balance the number of blanks on the two sides. More specifically, for the first and every other such row (11st, 33rd, 55th, and so forth), she would like ll to be less than rr. For the other rows (22nd, 44th, 66th, and so forth), she would like ll to be greater than rr.

What would the sign look like after Amanda sets it up according to the above?

입력

The first line of input contains two integers rr and cc (1≤r,c≤501 ≤ r, c ≤ 50), the number of rows and the number of columns of display units.

The next rr lines each contain a word with at least one and at most cc lowercase letters (a-z), giving the words to display per row in order.

출력

Output rr lines. Each line must contain exactly cc characters representing the displayed characters on one row of the LED sign. Output a dot (.) for each blank display unit.

예제1

  1. 예제 1

    입력
    8 7
    welcome
    we
    are
    open
    free
    coffee
    for
    icpc
    
    예상 출력
    welcome
    ..we...
    ..are..
    ..open.
    .free..
    .coffee
    ..for..
    .icpc..