Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- bool checkV(char * C, int m, int n, char * P, int lung, int posM, int posN){
- cout << "Looking for vertical match in " << posN << "-" << posN+lung-1 << "..\n";
- for (int j=posN; j<posN+lung; j++){
- int startM = posM-(j-posN); cout << "Starting from " << startM << "x" << j << "\n";
- int c = 0;
- if (startM>=0 && startM+lung<=m)
- for (int i=startM; i<startM+lung; i++){
- cout << i << "x" << j << ": " << C[i*n+j] << " ";
- if (C[i*n+j]==P[c]){ cout << ((c==lung-1) ? "MATCH\n" : "found\n");
- if (c==lung-1) return true;
- c++;
- }else cout << "nothing to do\n";
- }
- else cout << "There is not enough space in this column\n";
- }
- return false;
- }
- bool check(char * C, int m, int n, char * P, int lung){
- cout << "Looking for horizontal match..\n";
- for (int i=0; i<m; i++){
- int c = 0;
- for (int j=0; j<n; j++){ cout << i << "x" << j << ": " << C[i*n+j] << " ";
- if (C[i*n+j]==P[c]){ cout << ((c==lung) ? "MATCH\n" : "found\n");
- if (c==lung-1 && checkV(C, m, n, P, lung, i, j-c))
- return true;
- c++;
- }else if (n-j<=lung){ cout << "not enough space left in this row\n";
- break;
- }else cout << "nothing to do\n";
- }
- }
- return false;
- }
- int main(){
- int m = 6, n=8;
- char C[48] = {
- 'a', 's', 'd', 'p', 'g', 'h', 'j', 'p',
- 'e', 'r', 'p', 'i', 'p', 'p', 'o', 'i',
- 'r', 'r', 'i', 'l', 'h', '5', 'r', 'p',
- 'y', 'y', 'p', 'p', 'i', 'p', 'p', 'p',
- 't', 'y', 'o', 'p', 'i', 'p', 'p', 'o',
- 'f', 'g', 'r', 'w', 'a', 'r', 'g', 'h'
- };
- int lung = 5;
- char P[5] = {'p', 'i', 'p', 'p', 'o'};
- cout << check(&C[0], m, n, &P[0], lung) << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement