usaco transform

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yalishiyanzhouyu888/article/details/50659623
#include<stdio.h>
#include<stdlib.h>
char c[10][10],d[10][10],a[10][10],b[10][10];
int n;
bool pd(){
	int i,j;
	bool b=true;
	for(i=0;i<n;i++)
	  for(j=0;j<n;j++)
	    if(a[i][j]!=d[i][j])
	      b=false;
     return b;
}
bool work1(){
	int i,j;
	for(i=0;i<n;i++)
	  for(j=0;j<n;j++)
	    d[j][i]=c[n-i-1][j];
	return pd();
}
bool work2(){
	int i,j;
	for(i=0;i<n;i++)
	  for(j=0;j<n;j++)
	    d[i][j]=c[n-i-1][n-j-1];
	return pd();
}
bool work3(){
	int i,j;
	for(i=0;i<n;i++)
	  for(j=0;j<n;j++)
	    d[j][i]=c[i][n-j-1];
	return pd();
}
bool work4(){
	int i,j;
	for(i=0;i<n;i++)
	  for(j=0;j<n;j++)
	    d[i][j]=c[i][n-j-1];
	return pd();
}
bool work5(){
	int i,j;
	for(i=0;i<n;i++)
	  for(j=0;j<n;j++)
	    b[i][j]=c[i][n-j-1];
	for(i=0;i<n;i++)
	  for(j=0;j<n;j++)
	    d[j][i]=b[n-i-1][j];
	return pd();
}
bool work7(){
	int i,j;
	for(i=0;i<n;i++)
	  for(j=0;j<n;j++)
	    b[i][j]=c[i][n-j-1];
	for(i=0;i<n;i++)
	  for(j=0;j<n;j++)
	    d[i][j]=b[n-i-1][n-j-1];
	return pd();
}
bool work8(){
	int i,j;
	for(i=0;i<n;i++)
	  for(j=0;j<n;j++)
	    b[i][j]=c[i][n-j-1];
	for(i=0;i<n;i++)
	  for(j=0;j<n;j++)
	    d[j][i]=b[i][n-j-1];
	return pd();
}
bool work6(){
	int i,j;
	for(i=0;i<n;i++)
	  for(j=0;j<n;j++)
	    d[i][j]=c[i][j];
	return pd();
}
void work(){
	if(work1()) puts("1");
	else if(work2()) puts("2");
	else if(work3()) puts("3");
	else if(work4()) puts("4");
	else if(work5()) puts("5");
	else if(work7()) puts("5");
	else if(work8()) puts("5");
	else if(work6()) puts("6");
	else puts("7");
	return ;
}
int main(){
	int i,j,k,m;
	freopen("transform.in","r",stdin);
	freopen("transform.out","w",stdout);
	scanf("%d",&n);
	scanf("%*c");
	for(i=0;i<n;i++)
		gets(c[i]);
	for(i=0;i<n;i++)
		gets(a[i]);
	work();
	return 0;
}

阅读更多

usaco transform 功能错误,高手请指教

05-12

rn第一个test过了,第二个过不了rnrnrnrn#includernvoid change1(char c[10][10],char d[10][10],int a);/*旋转90*/rnvoid change2(char c[10][10],char d[10][10],int a);/*翻转*/rnint compare(char c[10][10],char d[10][10],int a);/*比较是否与目标矩阵一致*/rnint main()rn rn FILE *fin=fopen ("transform.in", "r");rn FILE *fout=fopen ("transform.out", "w");rnrn int a,i,j;rn char c[10][10],d[10][10],e[10][10];rn fscanf(fin,"%d",&a);/*行列数*/rn rn for(i=0;i<=(a-1);i++)rn for(j=0;j<=(a-1);j++)rn fscanf(fin," %c",&c[i][j]);rn d[i][j]=c[i][j];rn rn rn rn for(i=0;i<=(a-1);i++)rn for(j=0;j<=(a-1);j++)rn fscanf(fin," %c",&e[i][j]);rn rn rn if (compare(c,e,a)) fprintf(fout,"6\n");rn return 0;rn for(i=1;i<=3;i++)rn change1(c,d,a);rn if (compare(c,e,a)) fprintf(fout,"%d \n",i);rn return 0;rn rn change2(c,d,a);rn if (compare(c,e,a)) fprintf(fout,"5\n");rn return 0;rn for(i=1;i<=4;i++)rn change1(c,d,a);rn if (compare(c,e,a)&&(i==1)) fprintf(fout,"4\n");rn return 0;rn else if(compare(c,e,a)) fprintf(fout,"5\n");rn return 0;rn rn fprintf(fout,"7\n");rn return 0;rnrnrnrnvoid change1(char c[10][10],char d[10][10],int a)rnrn int n,m;rn for(n=0;n<=(a-1);n++)rn for(m=0;m<=(a-1);m++)rn c[n][m]=d[a-m-1][n];rnrnrnrnvoid change2(char c[10][10],char d[10][10],int a)rnrn int n,m;rn for(n=0;n<=(a-1);n++)rn for(m=0;m<=(a-1);m++)rn c[n][m]=d[n][a-m-1];rn rnrnrnint compare(char c[10][10],char d[10][10],int a)rnrn int n,m;rn for(n=0;n<=(a-1);n++)rn for(m=0;m<=(a-1);m++)rn if (c[n][m]!=d[n][m])rn return 0;rn return 1;rnrnrnrnrnrn----- our output ---------rn 5rn ---- your output ---------rn 7rn --------------------------rnrn ------ Data for Run 2 ------rn 5 rn -@@@- rn -@@-- rn -@--- rn ----- rn ----- rn ----- rn ----@ rn ---@@ rn --@@@ rn ----- rnrn

没有更多推荐了,返回首页