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

各位大牛,帮忙看一下,为什么老是wa啊!我用的是迭代

Posted by TITANIC111 at 2011-08-04 16:38:59 on Problem 2083
#include<iostream>
#include <math.h>
using namespace std;
int main()
{
	char a2[3][3]={{'X',' ','X'},{' ','X',' '},{'X',' ','X'}};
	char a[800][800]={' '},a3[300][300]={' '};
	int n,i,j,k,t1,t2;
	while (cin>>n)
	{
		if(n==-1) break;
		if(n==1) 
		{
			cout<<"X"<<endl;
			cout<<"-"<<endl;
			continue;
		}
		if(n==2) 
		{
			for(i=0;i<3;i++)
			{
				for(j=0;j<3;j++)
				cout<<a2[i][j];
				cout<<endl;
			}
			cout<<"-"<<endl;
			continue;
		}
		for(i=0;i<3;i++)
			for(j=0;j<3;j++)
				a3[i][j]=a2[i][j];
		for (i=3;i<=n;i++)
		{
			t1=powf(3,i-1);
			t2=t1/3;
			for (j=0;j<t2;j++)
				for(k=0;k<t2;k++)
				{
					a[j+t2][k+t2]=a3[j][k];
						a[j+2*t2][k+2*t2]=a3[j][k];
						a[j][k]=a3[j][k];
				}//到此只生成矩阵的一半,下面通过两次转置得到完整的输出图形
				for(j=0;j<=t1/2;j++)//转置一,处理上半部分
					for(k=0;k<t1/2;k++)
					 a[j][t1-k-1]=a[j][k];
					for(j=t1/2+1;j<t1;j++)//转置二,处理下半部分
						for(k=0;k<t1/2;k++)
							a[j][k]=a[j][t1-k-1];
				if(i!=n)
				for(j=0;j<300;j++)
					for(k=0;k<300;k++)
				     a3[j][k]=a[j][k];
		}
		t1=powf(3,n-1);
		for(i=0;i<t1;i++)
		{
			for(j=0;j<t1;j++)
				cout<<a[i][j];
			cout<<endl;
		}
		cout<<"-"<<endl;
	}
	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