daily pastebin goal
27%
SHARE
TWEET

T

a guest Jan 20th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. bool word_in_net(unsigned int gridRows, unsigned int gridColumns,char word[101], char grid[100][100]) {
  5.     unsigned int word_length= strlen(word);
  6.     for (int r = 0; r < gridRows; r++) {
  7.         for (int c = 0; c < gridColumns; c++) {
  8.             if (grid[r][c] == word[0] && c + word_length <= gridColumns) {
  9.                 int n = 0;
  10.                 while (grid[r][c + n] == word[n] && word[n]) {
  11.                     n++;
  12.                 }
  13.                 if (n== word_length) {
  14.                     return true;
  15.                 }
  16.             }
  17.         }
  18.     }
  19.    
  20.     for (int r = 0; r< gridColumns; r++) {
  21.         for (int c= 0; c < gridRows; c++) {
  22.             if (grid[c][r] == word[0] && c + word_length<= gridRows) {
  23.                 int n = 0;
  24.                 while (grid[c + n][r] == word[n] && word[n]) {
  25.                     n++;
  26.                 }
  27.                 if (n== word_length) {
  28.                     return true;
  29.                 }
  30.             }
  31.         }
  32.     }
  33.     return false;
  34. }
  35.  
  36. unsigned int countWords(char words[50][101], unsigned int numWords,
  37.     char grid[100][100], unsigned int gridRows,
  38.     unsigned int gridColumns) {
  39.     unsigned int words_numbers = 0;
  40.     for (int w = 0; w < numWords; w++) {
  41.         if (word_in_net(words[w], grid, gridRows, gridColumns))
  42.             words_numbers++;
  43.     }
  44.     return word_numbers;
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top