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

## 我的算法哪里错了？？

Posted by evil at 2004-05-09 12:09:29 on Problem 1128
```新手，请多帮助。

#include<stdio.h>
#include<string.h>
int a[5],h,w,up[5],down[5],left[5],right[5],num;
char s[31][31],z[125][6];
void search(int k)
{
int m,n,e;
if(k==5)
{
for(int x=0;x<5;x++)
z[num][x]=a[4-x]+'A';
z[num][5]='\0';
num++;
}
for(int i=4;i>-1;)
{
a[k]=i;
for(int j=0;j<k;j++)
if(a[k]==a[j]) goto tt;
for(m=up[i];m<=down[i];)
{
e=s[m][left[i]]-'A';
for(n=0;n<=k;n++)
if(a[n]==e)goto aa;
goto tt;
aa:			e=s[m][right[i]]-'A';
for(n=0;n<=k;n++)
if(a[n]==e)goto bb;
goto tt ;
bb:			m++;
}
for(m=left[i];m<=right[i];)
{
e=s[up[i]][m]-'A';
for(n=0;n<=k;n++)
if(a[n]==e)goto cc;
goto tt;
cc:			e=s[down[i]][m]-'A';
for(n=0;n<=k;n++)
if(a[n]==e)goto dd;
goto tt;
dd:			m++;
}
search(k+1);
tt:		i--;
}
}
int main()
{
int i,j;
while(scanf("%d%d",&h,&w)!=-1)
{
for(i=0;i<h;i++)
scanf("%s",&s[i]);
for(i=0;i<5;i++)
{
up[i]=h;
left[i]=w;
right[i]=down[i]=0;

}
for(i=0;i<h;i++)
for(j=0;j<w;j++)
{
if(s[i][j]>='A'&&s[i][j]<='E')
{
int w=s[i][j]-'A';
if(up[w]>i)up[w]=i;
if(down[w]<i)down[w]=i;
if(left[w]>j)left[w]=j;
if(right[w]<j)right[w]=j;
}
}

num=0;
search(0);
for(i=0;i<num;i++)
for(j=i+1;j<num;j++)
if(strcmp(z[i],z[j])>0)
{
char d[10];
strcpy(d,z[i]);
strcpy(z[i],z[j]);
strcpy(z[j],d);
}
for(i=0;i<num;i++)
printf("%s\n",z[i]);

}
return 0;
}```

Followed by: