Here is my code,the output is the same to the expected .i don't why it failed.Anyone can help?

```
class Solution {
public:
string convert(string s,int numRows){
if(s.length()<3) return s;
int rows = s.length(),lines=numRows;
char data[1000][1000] = {0};
int count = 0;
string ans;
int i=0,j=0,z=0;
while(count < s.length()){
for (j = 0; j < lines; ++j)
{
data[j][i] = s[count++];
}
i++;
for (z = j-2; z > 0; z--,i++)
{
data[z][i] = s[count++];
}
}
for (int i = 0; i < lines; ++i)
{
for (int j = 0; j < rows; ++j)
{
if(data[i][j]!=0) ans.push_back(data[i][j]);
}
}
ans.push_back('\0');
return ans;
}
};
```