Доброго времени суток!
У меня появилась проблема в следуемый код:
C++ |
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
| void __fastcall TForm7::Button2Click(TObject *Sender)
{
//citire
std::fstream os;
os.open("castel.txt");
int n,m,a[100][100];
os>>n>>m;
for (int i=0;i<n;i++)
for (int j=0;j<m;j++) os>>a[i][j];
//inregistrarea celulelor
int i1,i2,j1,j2;
i1=Edit1->Text.ToInt();
i2=Edit2->Text.ToInt();
j1=Edit3->Text.ToInt();
j2=Edit4->Text.ToInt();
//atribuirea cifrelor
int k1,k2;
k1=a[i1][j1];
k2=a[i2][j2];
//cod binar k1
int w1,n1,e1,s1;
if(k1%2==0) {k1=k1/2; w1=0;}
else {k1=k1/2; w1=1;}
if(k1%2==0) {k1=k1/2; n1=0;}
else {k1=k1/2; n1=1;}
if(k1%2==0) {k1=k1/2; e1=0;}
else {k1=k1/2; e1=1;}
if(k1%2==0) {k1=k1/2; s1=0;}
else {k1=k1/2; s1=1;}
//cod binar k2
int w2,n2,e2,s2;
if(k2%2==0) {k2=k2/2; w2=0;}
else {k2=k2/2; w2=1;}
if(k2%2==0) {k2=k2/2; n2=0;}
else {k2=k2/2; n2=1;}
if(k2%2==0) {k2=k2/2; e2=0;}
else {k2=k2/2; e2=1;}
if(k2%2==0) {k2=k2/2; s2=0;}
else {k2=k2/2; s2=1;}
//verificarea celulelor
if (i1==i2)//aceiasi linie
{
if (j1==j2-1)
{
if ((e1=='1')&&(w2=='1')) {e1=0;w2=0;}
}
else if(j1==j2+1)
{
if ((w1=='1')&&(e2=='1')) {w1=0;e2=0;}
}
}
else
if (j1==j2)//aceiasi coloana
{
if (i1==i2-1)
{if ((n1=='1')&&(s2=='1')) {n1=0;s2=0;}}
else if(i1==i2+1)
{if ((s1=='1')&&(n2=='1')) {s1=0;n2=0;}}
}
else ShowMessage("Nu se afla alaturi!!!");
//crearea fisierului ss.txt
std::fstream ss;
ss.open("sss.txt");
int c1,c2;
ss<<w1<<n1<<e1<<s1<<" "<<w2<<n2<<e2<<s2;
ss>>c1>>c2;
//convert to decimal c1
long dec1 = 0, rem1, base1 = 1;
while (c1 > 0)
{
rem1 = c1 % 10;
dec1 = dec1 + rem1 * base1;
base1 = base1 * 2;
c1 = c1 / 10;
}
a[i1][j1]=dec1;
//convert to decimal c2
long dec2 = 0, rem2, base2 = 1;
while (c2 > 0)
{
rem2 = c2 % 10;
dec2 = dec2 + rem2 * base2;
base2 = base2 * 2;
c2 = c2 / 10;
}
a[i2][j2]=dec2;
//inscrierea datelor
std::fstream s;
s.open("demolate.txt");
for (int i=0;i<n;i++){
for (int j=0;j<m;j++){ s<<a[i][j]<<" ";}s<<endl;}
} |
|
вот задание:
у меня есть замок с числами допустим
3 3(n и m)
1 2 3
15 10 6
4 7 2
эти цифры отвечают за комнаты этого замка то есть перевернутые в бинарный отвечают за стену замка
(1- стена,0 нет стены). Мне нужно удалить одну стену которая соединяет 2 комнаты.Удаляет ту стену которая между этих 2 комнат.Программа работает но не удаляет правильно стены, и самое главное остальные стены не должны поменяться.
Если по кратному код должен работать так:
1. читает из файла
2.конвертирует в бинарный
3. меняет бинарное число
4.конвертирует в десятичною бинарное число
5. записывает в файл
Так же мне нужно обратный код
вот что у меня получилось:
C++ |
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
| //citire
std::fstream os;
os.open("castel.txt");
int n,m;
os>>n>>m;
for (int i=0;i<n;i++)
for (int j=0;j<m;j++) os>>a[i][j];
//inregistrarea celulelor
int i1,i2,j1,j2;
i1=Edit1->Text.ToInt();
i2=Edit2->Text.ToInt();
j1=Edit3->Text.ToInt();
j2=Edit4->Text.ToInt();
//atribuirea cifrelor
int k1,k2;
k1=a[i1][j1];
k2=a[i2][j2];
//cod binar k1
int w1,n1,e1,s1;
if(k1%2==0) {k1=k1/2; w1=0;}
else {k1=k1/2; w1=1;}
if(k1%2==0) {k1=k1/2; n1=0;}
else {k1=k1/2; n1=1;}
if(k1%2==0) {k1=k1/2; e1=0;}
else {k1=k1/2; e1=1;}
if(k1%2==0) {k1=k1/2; s1=0;}
else {k1=k1/2; s1=1;}
//cod binar k2
int w2,n2,e2,s2;
if(k2%2==0) {k2=k2/2; w2=0;}
else {k2=k2/2; w2=1;}
if(k2%2==0) {k2=k2/2; n2=0;}
else {k2=k2/2; n2=1;}
if(k2%2==0) {k2=k2/2; e2=0;}
else {k2=k2/2; e2=1;}
if(k2%2==0) {k2=k2/2; s2=0;}
else {k2=k2/2; s2=1;}
//verificarea celulelor
if (i1==i2)//aceiasi linie
{
if (j1==j2-1)
{
if ((e1=='0')&&(w2=='0')) {e1=1;w2=1;}
}
else if(j1==j2+1)
{
if ((w1=='0')&&(e2=='0')) {w1=1;e2=1;}
}
}
else
if (j1==j2)//aceiasi coloana
{
if (i1==i2-1)
{if ((n1=='0')&&(s2=='0')) {n1=1;s2=1;}}
else if(i1==i2+1)
{if ((s1=='0')&&(n2=='0')) {s1=1;n2=1;}}
}
else ShowMessage("Nu se afla alaturi!!!");
//crearea fisierului ss.txt
std::fstream ss;
ss.open("ss.txt");
int c1,c2;
ss<<w1<<n1<<e1<<s1<<" "<<w2<<n2<<e2<<s2;
ss>>c1>>c2;
//convert to decimal c1
long dec1 = 0, rem1, base1 = 1;
while (c1 > 0)
{
rem1 = c1 % 10;
dec1 = dec1 + rem1 * base1;
base1 = base1 * 2;
c1 = c1 / 10;
}
a[i1][j1]=dec1;
//convert to decimal c2
long dec2 = 0, rem2, base2 = 1;
while (c2 > 0)
{
rem2 = c2 % 10;
dec2 = dec2 + rem2 * base2;
base2 = base2 * 2;
c2 = c2 / 10;
}
a[i2][j2]=dec2;
//inscrierea datelor
std::fstream s;
s.open("Add.txt");
for (int i=0;i<n;i++){
for (int j=0;j<m;j++){ s<<a[i][j]<<" ";}s<<endl;}
} |
|
Помогите пожалуйста!Буду благодарен. Заранее спасибо.