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

为什么输出时用putchar()不会超时而用printf("%c")就会超时

Posted by 20192661 at 2021-05-30 19:13:59 on Problem 2083
#include <stdio.h>
#include <math.h>
#include <string.h>
char a[729][729];
void fill(int x,int y,int n)
{
	if (n==1)
		a[x][y]='X';
	else
	{
		int t=(int)pow(3,n-2);
		fill(x,y,n-1);
		fill(x,y+2*t,n-1);
		fill(x+t,y+t,n-1);
		fill(x+2*t,y,n-1);
		fill(x+2*t,y+2*t,n-1);
	}
}
int main()
{
	memset(a,' ',sizeof(a));
	fill(0, 0, 7);
	int i,j,n;
	while(1)
	{
		scanf("%d", &n);
		if (n==-1) return 0;
		int m=(int)pow(3,n-1);
		for (i=0;i<m;i++)
		{
			for(j=0;j<m;j++)
				putchar(a[i][j]);
                                //改为printf("%c",a[i][j])就会超时
			putchar('\n');
		}
		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