这类题目主要是找到题目中隐含的规律,然后在进行编程处理。
string convert(string s, int numRows)
{
int length=s.length();
string result;
if(length==0||numRows==0||numRows==1) return s;
int nodeLen=2*numRows-2;
for (int i = 0; i < numRows; i++)
for (int j = i; j < length; j += nodeLen)
{
result += s[j];
if (i != 0 && i != numRows-1 && j - 2*i + nodeLen < length)
result += s[j - 2*i + nodeLen];
}
return result;
}