```
class Solution {
public:
string convert(string s, int nRows) {
if(nRows == 1) return s;
string* rows = new string[nRows];
int pi;//determine the row number
for(int i = 0; i < s.size(); i++){
pi = i%(2*nRows-2);
if(pi >= nRows){ pi = 2*nRows-2-pi;}
rows[pi] += s[i];
}
string result;
for(int i = 0; i < nRows; i++){
result = result + rows[i];
}
return result;
}
};
```