Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
非二维数组做法。只用一次循环输出 其实就是把要输出的第i个char与输入的位置算下对应关系 小心算,很容易错。 这样也比较快 0ms #include <stdio.h> #include <string.h> #include <math.h> int main() { float r,c,rp,cp,len; float i,locate; char data[205]; while(scanf("%f",&c),c!=0) { scanf("%s",&data); len = (float)strlen(data); r = (float)ceil(len/c); for(i=1;i<=len;i++) { cp = (float)ceil(i/r); rp = i - (cp-1) * r; if((int)rp%2) locate = (rp-1) * c + cp; else locate = (rp-1) * c + (c - cp + 1); printf("%c",data[(int)locate - 1]); } printf("\n"); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator