Welcome to ZOJ
Information
Select Problem
Runs
Ranklist
ZOJ Problem Set - 3481
Expand Tab

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Tab key (abbreviation of tabulator key) on a keyboard is used to advance the cursor to the next tab stop. Though the tab key rarely has the effect of inserting the tab character in modern applications, they are still widely used by many programmers to indent their source code.

Here comes the tabs-versus-spaces argument. Some programmers insist that only space characters should be used for portability. In an editor that uses a fixed-width font, tab stops are placed at different intervals (commonly every eight or four characters) in different operating systems and user environment. This means that no matter what your personal beliefs are about where tabs belong, you can't rely on someone else's editor honoring your preferences. Indentation with tabs may look bad in other environment. Converting tabs to space characters avoids this problem entirely.

You want to convert all the tabs in some files to appropriate number of spaces. After the conversion, the content should have the same appearance with the original one under the specified tab stops configuration. The tab always expands to at least one space and indents to the smallest possible tab stop. There are two forms of tab stops configuration. In the first form, only one tab stop ts is given, and it sets the tabs ts apart. For example, if ts=4, then the tab indents to column 4, 8, 12, …. In the second form, a list of tab stops separated by commas ts1,ts2,… is given, and it sets the tabs at column ts1, ts2, …, and replaces any tabs beyond the largest tab stop given with single spaces. For example, the tab stops list 6,8,10 is equivalent to 6, 8, 10, 11, 12, 13, ….

Input

There are multiple test cases. The first line of input is an integer T ≈ 100 indicating the number of test cases.

Each test case has the following form:

expand tab-stops-configuration <<delimiting-identifier
multi-line-contents
delimiting-identifier
an-empty-line

where tab-stops-configuration is either a positive integer or a list of positive integers separated by commas, no tab stop exceeds 1000, no line's length exceeds 1000. The contents are given by here document (also called heredoc, hereis, here string), whose syntax is << followed by a delimiting identifier, followed, starting on the next line, by the text to be quoted, and then closed by the same identifier on its own line. The delimiting-identifier is a sequence of one or more ASCII letters, digits (these may not appear as the first character), and underscores.

Output

For each statement, output the content after converting tabs to appropriate number of spaces according to the given tab stops configuration. Output a blank line after each test case.

Sample Input

3
expand 4,8,4 <<comment
# vim: ft=ruby ts=4 sw=4 noet nonu
# vim: list listchars=tab\:>-,trail\:-
comment

expand 4 <<Ruby
#{
	def fib(n)
		n < 2 ? 1 : fib(n - 1) + fib(n - 2)
	end

	[*1 .. 10].each{|_| p fib(_) if _.odd?}
}
Ruby

expand 6,8,10 <<FORTRAN
C	there	are	some	trailing	spaces  
	program EMP
	do 10 while (.true.)
		read(*,*,iostat=ios) n, m
		if (ios < 0) exit
10		write(*,*) n + m
	end program EMP
FORTRAN

Sample Output

# vim: ft=ruby ts=4 sw=4 noet nonu
# vim: list listchars=tab\:>-,trail\:-

#{
    def fib(n)
        n < 2 ? 1 : fib(n - 1) + fib(n - 2)
    end

    [*1 .. 10].each{|_| p fib(_) if _.odd?}
}

C     there are some trailing spaces  
      program EMP
      do 10 while (.true.)
        read(*,*,iostat=ios) n, m
        if (ios < 0) exit
10      write(*,*) n + m
      end program EMP

References


Author: WU, Zejun
Contest: The 11th Zhejiang University Programming Contest
Submit    Status