模拟。注意当nRows = 1的情况。
class Solution {
public:
string convert(string s, int nRows) {
if(nRows == 1) return s;
string ans;
for(int i = 0; i < nRows; i++){
int j = i;
bool tag = true;
while(j < s.size()){
ans += s[j];
if(i == 0 || i == nRows-1){
j += (nRows-1)*2;
}
else{
if(tag){
j += (nRows-i-1)*2;
}
else{
j += i*2;
}
tag = !tag;
}
}
}
return ans;
}
};