Z字形变换

《Z字形变换》

这类题目主要是找到题目中隐含的规律,然后在进行编程处理。

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;
}

    原文作者:Z字形编排问题
    原文地址: https://blog.csdn.net/zhumengduan3526/article/details/80500984
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞