for this problem,
you must divided the problem into two part.
then find the change rule. the precise rule please see it in the code bellow.
class Solution {
public:
string convert(string s, int nRows) {
if(s == "" || s.length() < nRows || nRows <=1)
return s;
string q = "";
for(int i = 0;i<s.length();i += (nRows-1)*2)
q = q + s[i];
for(int i = 1;i<nRows-1; i++)
for(int j = i;j<s.length();j = j+(nRows-1)*2)
{
q = q+s[j];
if(j+(nRows-i-1)*2 < s.length())
q = q+s[j+(nRows-i-1)*2];
}
for(int i = nRows-1;i<s.length();i += (nRows-1)*2)
q = q + s[i];
return q;
}
};