Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- char str[102][102];
- string s;
- int n;
- struct point
- {
- int x,y;
- } v;
- bool bfs(point ind,int X,int Y)
- {
- queue<point>Q;
- point dir;
- dir.x = X;
- dir.y = Y;
- Q.push(ind);
- int l = 1;
- while(!Q.empty() && l<s.length())
- {
- point u = Q.front();
- Q.pop();
- v.x = u.x+dir.x;
- v.y = u.y+dir.y;
- if(v.x>=0 && v.y>=0 && v.x<n && v.y<n && s[l]==str[v.x][v.y])
- {
- Q.push(v);
- l++;
- }
- }
- if(l==s.length())
- return true;
- return false;
- }
- int main()
- {
- int i,j;
- scanf("%d",&n);
- getchar();
- for(i=0; i<n; i++)
- {
- gets(str[i]);
- }
- while(cin>>s)
- {
- if(s[0]=='0')
- break;
- bool dhukse = false;
- for(i=0; i<n; i++)
- {
- for(j=0; j<n; j++)
- {
- if(s[0]==str[i][j])
- {
- point ind;
- ind.x = i;
- ind.y = j;
- if(bfs(ind,1,1)||bfs(ind,0,1)||bfs(ind,1,0)||bfs(ind,1,-1)||bfs(ind,0,-1)||bfs(ind,-1,0)||bfs(ind,-1,1)||bfs(ind,-1,-1))
- {
- printf("%d,%d %d,%d\n",i+1,j+1,v.x+1,v.y+1);
- dhukse = true;
- break;
- }
- }
- }
- if(dhukse)
- {
- break;
- }
- }
- if(!dhukse)
- {
- printf("Not found\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment