#C923. Zigzag Conversion
Zigzag Conversion
Zigzag Conversion
Given a string s
and an integer numRows
, convert s
into a zigzag pattern on numRows
rows and then read the pattern line by line.
The zigzag pattern is created by writing the characters of s
in a down-and-up diagonal fashion across rows. For example, when \(s = \texttt{PAYPALISHIRING}\) and \(numRows = 4\), the zigzag pattern looks like:
P I N A L S I G Y A H R P I
Reading line by line, the output is PINALSIGYAHRPI
.
If numRows
is 1 or greater than or equal to the length of s
, the output is the original string.
inputFormat
The input consists of two lines read from standard input:
- The first line contains the string
s
. - The second line contains the integer
numRows
.
Both inputs are guaranteed to be valid.
outputFormat
Output a single line containing the string obtained after converting s
into its zigzag pattern.
PAYPALISHIRING
4
PINALSIGYAHRPI