char * convert(char * s, int numRows){ if (numRows < 2) return s; int i, j, pst = 0, len = strlen(s), cnt; char* retStr = (char*)calloc(len + 1, sizeof(char)); for (i = 0; i<numRows; i++){ for (j = i, cnt = 0; j<len; cnt++){ retStr[pst++] = s[j]; j += ( i!=numRows-1 && (cnt % 2 == 0 || i == 0) ) ? (numRows - 1 - i) * 2 : i * 2; } } /*for (i = numRows - 1; i<len; i += (numRows - 1) * 2) retStr[pst++] = s[i];*/ return retStr; }
原文:https://www.cnblogs.com/ganxiang/p/14095133.html