arrays - crossword game: read 2d given diagonally c++ -


i wanna read array this cross word game should find word in on 2d given array array read given file , n *m size; m not = n

a b c d e f g h j k l m n o q r s t u v x y z

how can read 2d given diagonally this: of posible::

1:mu 2:gnv - diagonally b c d e f [g] h j k l m [n] o q r s t u [v] x y z 3:ahox 4:ahox 5:ciqy 6:eks 

real example

m=4 n=4 b o o k z k o s l l e x y z l  ball: found foo: not found 

char readrc(char* array, int r, int c, int n, int m) {    return (r > 0 && r <= n && c > 0 && c <= m) ?                   array[n * (r - 1) + (c - 1)] : '\0'; }  void read_down_right(char* array, int n, int m, vector<string>& list) {    (int sc = 2 - n; sc <= m - 1; sc++)    {         string str = "";       (int r = 1, c = sc; r <= n; r++, c++)       {          char chr = readrc(array, r, c, n, m);          if (chr != '\0')             str += chr;       }       list.push_back(str);    } }  void read_down_left(char* array, int n, int m, vector<string>& list) {    (int sc = 2; sc <= m + n - 2; sc--)    {        string str = "";       (int r = 1, c = sc; r <= n; r++, c--)       {          char chr = readrc(array, r, c, n, m);          if (chr != '\0')             str += chr;       }       list.push_back(str);    } } 

pass reference blank list each time. list contains possible strings afterwards, linear search.


Comments