Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. #define MAX_TAM 600
  7.  
  8. char Ni[20];
  9. int table[MAX_TAM][MAX_TAM], ans, T, Q;
  10.  
  11. void solve_for_this (int l, int c, int len, int tam)
  12. {
  13.     if (l < 0 || l > T - 1 || c < 0 || c > T - 1)
  14.         return;
  15.  
  16.     if (table[l][c] != (int) Ni[tam - 1] - '0')
  17.         return;
  18.    
  19.     if (tam == len)
  20.         ans++;
  21.        
  22.     solve_for_this (l + 1, c, len, tam + 1);
  23.     solve_for_this (l - 1, c, len, tam + 1);
  24.     solve_for_this (l, c + 1, len, tam + 1);
  25.     solve_for_this (l, c - 1, len, tam + 1);
  26. }
  27.  
  28. void input ()
  29. {
  30.     int len = 0;
  31.    
  32.     scanf ("%d", &T);
  33.    
  34.     for (int k = 0; k < T; k++)
  35.         for (int i = 0; i < T; i++)
  36.             scanf ("%d", &table[k][i]);
  37.            
  38.     scanf ("%d", &Q);
  39.     for (int k = 0; k < Q; k++)
  40.     {
  41.         ans = 0;
  42.         scanf ("%s", Ni);
  43.         len = strlen (Ni);
  44.        
  45.         for (int j = 0; j < T; j++)
  46.             for (int i = 0; i < T; i++)
  47.                 solve_for_this (j, i, len, 1);
  48.        
  49.         printf ("%d\n", ans);
  50.     }
  51. }
  52.  
  53. int main ()
  54. {
  55.     input ();
  56.    
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement