Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstring>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. using namespace std;
  8.  
  9. bool checkRight(vector < vector<char> > &matrix, char *word) {
  10.  
  11.   bool result = false;
  12.   int counter = 0;
  13.   /*if (strlen(word) > (matrix.size()-y)) {  
  14.       return false;
  15.   }*/
  16.  
  17.     for(int i = 0; i < matrix.size(); i++){
  18.         for(int j = 0; j < matrix.size(); j++){
  19.             if((word[counter] == matrix[i][j + 1]) && (counter < strlen(word))) {
  20.                 result = true;
  21.           counter++;
  22.           break;
  23.         }
  24.             else{
  25.                 result = false;
  26.         }
  27.  
  28.   }
  29.       return result;
  30. }
  31.  
  32. }
  33.  
  34.  
  35. bool checkLeft(vector < vector<char> > &matrix, char *word) {
  36.  
  37.   bool result = false;
  38.   /*if (strlen(word) > (matrix.size()-y)) {
  39.       return false;
  40.   }*/
  41.  
  42.     for(int i = 0; i < matrix.size(); i++){
  43.         for(int j = 0; j < matrix[i].size(); j++)
  44.             if(word[0] == matrix[i][j - 1])
  45.                 result = true;
  46.             else
  47.                 result = false;
  48.     }
  49.     return result;
  50.   }
  51.  
  52. bool checkDown(vector < vector<char> > &matrix, char *word) {
  53.  
  54.   bool result = false;
  55.   /*if (strlen(word) > (matrix.size()-y)) {
  56.       return false;
  57.   }*/
  58.  
  59.     for(int i = 0; i < matrix.size(); i++){
  60.         for(int j = 0; j < matrix[i].size(); j++)
  61.             if(word[0] == matrix[i + 1][j])
  62.                 result = true;
  63.             else
  64.                 result = false;
  65.     }
  66.     return result;
  67.   }
  68.  
  69. bool checkDiagRightUp(vector < vector<char> > &matrix, char *word) {
  70.  
  71.   bool result = false;
  72.   /*if (strlen(word) > (matrix.size()-y)) {
  73.       return false;
  74.   }*/
  75.  
  76.     for(int i = 0; i < matrix.size(); i++){
  77.         for(int j = 0; j < matrix[i].size(); j++)
  78.             if(word[0] == matrix[i - 1][j + 1])
  79.                 result = true;
  80.             else
  81.                 result = false;
  82.     }
  83.     return result;
  84.   }
  85.  
  86.  
  87. bool checkDiagRightDown(vector < vector<char> > &matrix, char *word) {
  88.  
  89.   bool result = false;
  90.   /*if (strlen(word) > (matrix.size()-y)) {
  91.       return false;
  92.   }*/
  93.  
  94.     for(int i = 0; i < matrix.size(); i++){
  95.         for(int j = 0; j < matrix[i].size(); j++)
  96.             if(word[0] == matrix[i + 1][j + 1])
  97.                 result = true;
  98.             else
  99.                 result = false;
  100.     }
  101.     return result;
  102.   }
  103.  
  104.  
  105.  bool checkDiagLeftUp(vector < vector<char> > &matrix, char *word) {
  106.  
  107.   bool result = false;
  108.   /*if (strlen(word) > (matrix.size()-y)) {
  109.       return false;
  110.   }*/
  111.  
  112.     for(int i = 0; i < matrix.size(); i++){
  113.         for(int j = 0; j < matrix[i].size(); j++)
  114.             if(word[0] == matrix[i - 1][j - 1])
  115.                 result = true;
  116.             else
  117.                 result = false;
  118.     }
  119.     return result;
  120.   }
  121.  
  122.  bool checkDiagLeftDown(vector < vector<char> > &matrix, char *word) {
  123.  
  124.   bool result = false;
  125.   /*if (strlen(word) > (matrix.size()-y)) {
  126.       return false;
  127.   }*/
  128.  
  129.     for(int i = 0; i < matrix.size(); i++){
  130.         for(int j = 0; j < matrix[i].size(); j++)
  131.             if(word[0] == matrix[i + 1][j - 1])
  132.                 result = true;
  133.             else
  134.                 result = false;
  135.     }
  136.     return result;
  137.   }
  138.  
  139.   bool checkUp(vector < vector<char> > &matrix, char *word) {
  140.  
  141.   bool result = false;
  142.   /*if (strlen(word) > (matrix.size()-y)) {
  143.       return false;
  144.   }*/
  145.  
  146.     for(int i = 0; i < matrix.size(); i++){
  147.         for(int j = 0; j < matrix[i].size(); j++)
  148.             if(word[0] == matrix[i-1][j])
  149.                 result = true;
  150.             else
  151.                 result = false;
  152.     }
  153.     return result;
  154.   }
  155.  
  156.  
  157. int main(int argc, char *argv[]) {
  158.  
  159.   int x;
  160.   int y;
  161.  
  162.   cin >> x;
  163.   cin >> y;
  164.  
  165.   vector< vector<char> > matrix;
  166.  
  167.   matrix.resize(x);
  168.   for(int i = 0; i < matrix.size(); i++)
  169.     matrix[i].resize(y);
  170.  
  171.   for (int i = 0; i < x; i++)
  172.     for (int j = 0; j < y; j++)
  173.       cin >> matrix[i][j];
  174.  
  175.   for (int i = 0; i < x; i++) {
  176.     for (int j = 0; j < y; j++)
  177.       cout << matrix[i][j] << " ";
  178.     cout << endl;
  179.   }
  180.  
  181.     bool isCheckRight = checkRight(matrix, argv[1]);
  182.     /*bool isCheckUp = checkUp(matrix, argv[1]);
  183.     bool isCheckLeft = checkLeft(matrix, argv[1]);
  184.     bool isCheckDown = checkDown(matrix, argv[1]);
  185.     bool isCheckDiagRightUp = checkDiagRightUp(matrix, argv[1]);
  186.     bool isCheckDiagRightDown = checkDiagRightDown(matrix, argv[1]);
  187.     bool isCheckDiagLeftUp = checkDiagLeftUp(matrix, argv[1]);
  188.     bool isCheckDiagLeftDown = checkDiagLeftDown(matrix, argv[1]);*/
  189.  
  190.     if (isCheckRight) {
  191.         cout << "true" << endl;
  192.     }
  193.     else{
  194.         cout << "false" << endl;
  195.     }
  196.  
  197.     /*if (isCheckUp) {
  198.         cout << "true" << endl;
  199.     }
  200.     else{
  201.         cout << "false" << endl;
  202.     }
  203.  
  204.     if (isCheckLeft) {
  205.         cout << "true" << endl;
  206.     }
  207.     else{
  208.         cout << "false" << endl;
  209.     }
  210.  
  211.  
  212.     if (isCheckDown) {
  213.         cout << "true" << endl;
  214.     }
  215.     else{
  216.         cout << "false" << endl;
  217.     }
  218.  
  219.  
  220.     if (isCheckDiagRightUp) {
  221.         cout << "true" << endl;
  222.     }
  223.     else{
  224.         cout << "false" << endl;
  225.     }
  226.  
  227.  
  228.     if (isCheckDiagRightDown) {
  229.         cout << "true" << endl;
  230.     }
  231.     else{
  232.         cout << "false" << endl;
  233.     }
  234.  
  235.     if (isCheckDiagLeftUp) {
  236.         cout << "true" << endl;
  237.     }
  238.     else{
  239.         cout << "false" << endl;
  240.     }
  241.  
  242.  
  243.     if (isCheckDiagLeftDown) {
  244.         cout << "true" << endl;
  245.     }
  246.     else{
  247.         cout << "false" << endl;
  248.     }*/
  249.  
  250.  
  251.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement