How to solve matrice crossword ?

Hello,
I have a table(matrice) with letter in each slot. i have file with it:
5 7
L a j i n i k
a K a m i n u
i s b i s a C
v i i G a i s
e l n e t t i
4
Kabinetas 2 2
Laivelis 1 1
Giminaitis 4 4
Cukinija 3 7

5 and 7 is matrice size, below is matrice. at the end there are 4 words i have to find and their first letter place in matrice.

My task is to find those 4 words and change matrice, crossed word is changed to number of word like this:
2 4 4 4 4 4 4
2 1 1 3 3 3 4
2 2 1 3 1 3 4
2 2 1 3 1 3 3
2 2 1 1 1 3 3

I did put matrice to class and to double massive (i dont actually know how it is called, but it looks like this: a[i][j];). I do understand that i need to look letters from the first one i have with if and +1 -1 on matrice axis. But problem is, that half word can be to wrong side, so if i go to wrong side, i will have to redo calculations. I understand what i have to do, but im not able to write it in any way. Can you plz get me on the way ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//------------- First class for matrice letters -------------------------------
/** class for matrice letters
class Raides
{
private:
	char raide;     // matrice letter

public:
	Raides(char Raide = ' '): raide(Raide) {}
	~Raides() {}
	void Deti(char Raide)
	{
		raide = Raide;
	}
	char ImtiRaide() {return raide;}
};

//------------------------- class for looking words -------------------------
#pragma once
#include <string>

using namespace std;

class Ieskoma
{
private:
	string zodis; // ieskomas zodis
	int x; // pozicija eiluteje
	int y; // pozicija stulpelyje
public:
	Ieskoma(): zodis(""), x(0), y(0) {}
	~Ieskoma(){}
	void Deti(string Zodis, int X, int Y)
	{
		zodis = Zodis;
		x = X;
		y = Y;
	}
	string ImtiZodi() {return zodis;}
	int ImtiX() {return x;}
	int ImtiY() {return y;}
};
//------------ conteiner class ----------------------------------
#include "Raides.h"
using namespace std;


/** class for crossword
class Kryziazodis
{
public:
	static const int Ceil = 100; // max number of lines
	static const int Cstulp = 100; // max number of columns
private:
	Raides R[Ceil][Cstulp];
	int n; // lines number
	int m; // columns number
public:
	Kryziazodis(int N = 0, int M = 0): n(N), m(M){}
	~Kryziazodis(){}
	int ImtiN() {return n;}
	int ImtiM() {return m;}
	void DetiN(int N) {n = N;}
	void DetiM(int M) {m = M;}
	void Deti(int i, int j, Raides r) {R[i][j] = r;}
	Raides Imti(int i, int j) {return R[i][j];}
};
//--------------------------------- main file--------------------------
#include "Kryziazodis.h"
#include <string>
#include <iomanip>
#include <fstream>
#include <iostream>
#include "Ieskoma.h"

using namespace std;
const char CDfv[] = "Duom.txt";
const char CRfr[] = "Rezultatai.txt";
const int Cmax = 100; // maximum ammount of words


void Skaityti(const char fv[], Kryziazodis & a, int & k, Ieskoma b[]);
void Spausdinti(const char fr[], Kryziazodis a, int k, Ieskoma b[]);
void RastiZodi(Kryziazodis a, Ieskoma b);

int main()
{
	Kryziazodis a;
	int k = 0; // number of looking words
	Ieskoma b[Cmax];
	Skaityti(CDfv, a, k, b);
	Spausdinti(CRfr, a, k , b);
	for (int i = 0; i < k; i++)
		RastiZodi(a, b[i]);
}

void Skaityti(const char fv[], Kryziazodis & a, int & k, Ieskoma b[])
{
	int n, m, x, y;
	char raide;
	Raides r;
	string zodis;
	ifstream fd(fv);
	fd >> n >> m;
	a.DetiN(n);
	a.DetiM(m);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
		{
			fd >> raide;
			r.Deti(raide);
			a.Deti(i, j, r);
		}
	fd >> k;
	for (int i = 0; i < k; i++)
	{
		fd >> zodis >> x >> y;
		b[i].Deti(zodis, x, y);
	}
	fd.close();
}

void Spausdinti(const char fr[], Kryziazodis a, int k, Ieskoma b[])
{
	ofstream fd(fr);
	for (int i = 0; i < a.ImtiN(); i++)
	{
		for (int j = 0; j < a.ImtiM(); j++)
			fd << a.Imti(i,j).ImtiRaide() << " ";
		fd << endl;
	}
	cout << a.Imti(2,2).ImtiRaide();
	fd << endl << k << endl;
	for (int i = 0; i < k; i++)
	fd << b[i].ImtiZodi() << " " << b[i].ImtiX() << " " << b[i].ImtiY() << endl;
	fd.close();
}

void RastiZodi(Kryziazodis a, Ieskoma b)
{
	int ilgis = b.ImtiZodi().length();
	char raide[50];
	for (int i = 0; i < ilgis; i++)
		raide[i] = b.ImtiZodi()[i];
	int x = b.ImtiX()-1;
	int y = b.ImtiY()-1;
	int ilg = 0;
	int vietaX[50];
	int vietaY[50];
	char tarp = a.Imti(x,y).ImtiRaide();
	while (ilg != ilgis)
	{
		if (a.Imti(x,y).ImtiRaide() == raide[0])
		{
			vietaX[ilg] = x;
			vietaY[ilg] = y;
			ilg++;
		}
	}
	

} */
Last edited on
Topic archived. No new replies allowed.