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 K208 at 2005-10-07 15:58:20 on Problem 1501
#include <stdio.h>
#include <string.h>

char a[100][102];  //储存矩阵

int main()
{
int n , i , j , L , k , find , x1 , y1 , x2 , y2 , t;
char s[102];

	scanf("%d" , &n);
	for (i = 0; i < n; i ++) scanf("%s" , a[i]);
	while (scanf("%s" , s) == 1)
	{
		if (s[0] == '0') break;
		L = strlen(s);
		if (L > n) {printf("Not found\n"); continue;}
		find = 0;
		for (i = 0; i < n; i ++)
		{
			for (j = 0; j < n; j ++)
				if (a[i][j] == s[0])
				{
					x1 = i + 1; y1 = j + 1;
					if (j + 1 >= L)   //Right To Left
					{
						find = 1; t = 0;
						for (k = j; k > j - L; k --) if (a[i][k] != s[t ++]) {find = 0; break;}
						if (find) {x2 = x1; y2 = y1 - L + 1; break;}
					}
					if (n - j >= L)   //Left To Right
					{
						find = 1; t = 0;
						for (k = j; k < j + L; k ++) if (a[i][k] != s[t ++]) {find = 0; break;}
						if (find) {x2 = x1; y2 = y1 + L - 1; break;}
					}
					if (i + 1 >= L)   //Down To Up
					{
						find = 1; t = 0;
						for (k = i; k > i - L; k --) if (a[k][j] != s[t ++]) {find = 0; break;}
						if (find) {x2 = x1 - L + 1; y2 = y1; break;}
					}
					if (n - i >= L)   //Up To Down
					{
						find = 1; t = 0;
						for (k = i; k < i + L; k ++) if (a[k][j] != s[t ++]) {find = 0; break;}
						if (find) {x2 = x1 + L - 1; y2 = y1; break;}
					}
				}
			if (find) break;
		}
		if (find) printf("%d,%d %d,%d\n" , x1 , y1 , x2 , y2);
		else printf("Not found\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