The string
"PAYPALISHIRING"
is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H N A P L S I I G Y I RAnd then read line by line:"PAHNAPLSIIGYIR"
Write the code that will take a string and make this conversion given a number of rows:
string convert(string text, int nRows);
convert("PAYPALISHIRING", 3)
should return"PAHNAPLSIIGYIR"
.
題目描述:
按照之字格式輸入數據,並且按照橫向輸出。
<喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+yOfNvKGjPC9wPgo8cD48YnI+CjwvcD4KPHA+veLM4su8wrejujwvcD4KPHA+PGJyPgo8L3A+CjxwPsnobs6qyuTI69DQyv2jrGnOqtDQusU8YnI+CjwvcD4KPHA+uduy7M28z/HRsNXSuebCyaGjPC9wPgo8cD7I57n7yse12jDQ0LrN1+6689K70NDDv7j219a3+9auvOS1xL7gwOvOqjIqbi0yPC9wPgo8cD7I57n7ysfW0Lzk0NCjrMj0uMPQ0MHQusXOqsW8yv3U8tPrz8K49tfWt/u+4MDrMioobi1pLTEpIKOst/HU8sj0zqrG5sr91PLT68/CuPbX1rf7z+C+4MDrMippPC9wPgo8cD48YnI+CjwvcD4KPHA+wP3I56O6PC9wPgo8cD7NvNbQy/nKvqOstdox0NCjrLXa0ru49tfWt/vOqjGjrMHQusXOqjCjrM6qxbzK/aOs1PLT67Xatv649r7gwOvOqjIqo6g1LTEtMaOpPTY8L3A+CjxwPry0z8K49tfWt/vOqjYmIzQzOzE9NzwvcD4KPHA+08nT2je1xNfWt/vB0LrFzqozzqrG5sr9o6zL+dLUz8K49tfWt/u1xMHQusW+4MDrzqoyKjE9MiC8tDcmIzQzOzI9OTwvcD4KPHA+PGJyPgo8L3A+CjxwPjxwcmUgY2xhc3M9"brush:java;">public class Solution { public String convert(String s, int nRows) { String res=""; int len=s.length(); if (nRows <= 1 || len == 0 ||len