Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. // PRE(T[limite_1][15][15] e' completamente definita, P[dim_P] e' completamente definita)
  6.  
  7. int F(char (*T)[3][3], int limite_1, char P[], int dim_P)
  8. {
  9.     int h = 0;
  10.     bool primo = false;
  11.     bool secondo = false;
  12.     bool ok = false;
  13.     int k = 0;
  14.     while(k < limite_1)
  15.     {
  16.         for(int i = 0;i < 3;i++)
  17.         {   for(int j = 0;j < 3;j++)
  18.             {  
  19.                 if((T[k][i][j] == P[h]) && (h < dim_P))
  20.                 {
  21.                     ok = true;
  22.                     h++;
  23.                 }
  24.                 else if((T[k][i][j] != P [h]) && (h < dim_P))
  25.                 {
  26.                     ok = false;
  27.                     h = 0;
  28.                 }
  29.                 if((h == dim_P - 1) && (ok))
  30.                 {
  31.                     primo = true;
  32.                 }
  33.                 if((h == dim_P - 1) && (ok) && (primo))
  34.                 {
  35.                     secondo = true;
  36.                 }
  37.             }
  38.         }
  39.         if(primo && secondo)
  40.         {
  41.             return k;
  42.         }
  43.         else
  44.         {
  45.             k++;
  46.         }
  47.     }
  48.     if(secondo == false)
  49.     {
  50.         return -1;
  51.     }
  52. }
  53.  
  54.  
  55. main()
  56. {
  57.     char R[2][3][3] = { 'a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h','s','o'};
  58.     char A[3] = {'a','c','b'};
  59.     int x = F(R,2,A,3);
  60.     cout << x << endl;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement