Xiaobaishu training-Where & #39; s Waldorf?
Question: Give an alphabet, then give several words, and ask where the first address of these words is in the alphabet.
Because it is difficult to search in eight orders, but it is not difficult to do it before. This time, the improvement is to use array + loop to control eight directions, instead of writing a lot of code in all directions.
Code:
#include
#include
#include
#include
using namespace std;int x[8] = {1,1,0,-1,-1,-1,0,1};int y[8] = {0,-1,-1,-1,0,1,1,1};int m,n;char s[50][50];char sk[50];int ok(int ix,int iy){ for(int i = 0;i < 8;i++) { char *p = sk; int j,k; for(j = ix,k = iy;(j >= 0 && j < n)&&(k >= 0 && k < m)&&*p != '';j += x[i],k += y[i],p++) { if(*p != s[j][k]) break; } if(*p == '') { return 1; } } return 0;}void find(){ for(int i=0;i
> N; while(N--) { cin >> n >> m; for(int i = 0;i < n;i++) cin >> s[i]; //zhuan huan wei xiao xie for(int i=0;i
> t; for(int i = 0;i < t;i++) { cin >> sk; int len = strlen(sk); for(int j = 0;j < len;j++) sk[j] = tolower(sk[j]); find(); } if(N) cout << endl; } return 0;}
Dream code: http://www.hypo.xyz