Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

非二维数组做法。

Posted by zgr0629 at 2009-04-06 19:23:14 on Problem 2039
只用一次循环输出

其实就是把要输出的第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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator