标签:tle logs png title 总结 record har back order
1 char* convert(char* s, int numRows) { 2 3 if(numRows == 1) { 4 return s; 5 } 6 7 char *p = (char *) malloc (sizeof(char) * 1000); 8 char *q = s; 9 int len = 0; 10 while(*q != ‘\0‘) { 11 len++; 12 q++; 13 } 14 15 int i=0; 16 int seq = 0; /* used to record current write position */ 17 int circle = 2 * numRows - 2; 18 for(i=0; i<numRows && i<len; i++) { 19 int a = i; 20 while(a<len) { 21 *(p+seq) = s[a]; 22 seq++; 23 if(0 <= a%circle && a%circle < circle/2) { 24 a = (a/circle * circle + circle/2)*2 - a; 25 } else { 26 a = (a/circle + 1) * circle * 2 - a; 27 } 28 } 29 } 30 *(p+seq) = ‘\0‘; 31 return p; 32 33 }
总结:
1. 忽略了circle为0的情况
2. 内存分配不熟悉
标签:tle logs png title 总结 record har back order
原文地址:http://www.cnblogs.com/tuhooo/p/7606555.html