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
| #pragma hdrstop
#pragma argsused
#ifdef _WIN32
#include <tchar.h>
#else
typedef char _TCHAR;
#define _tmain main
#endif
#include <stdio.h>
#include <iostream.h>
#include <string>
//------------------------------------------------------------------------------
struct train{
string FIO;
string vagon;
int place;
int cost;
int plackart;
train *next;
train *prev;};
//------------------------------------------------------------------------------
train * first(string F, string s, int h, int f,int p){
train *pv = new train;
pv->FIO = F;
pv->vagon = s;
pv->place = h;
pv->cost = f;
pv->plackart = p;
pv->next = 0;
pv->prev = 0;
return pv;}
//------------------------------------------------------------------------------
void add(train **pend, string F, string s, int h, int f, int p){
train *pv = new train;
pv->FIO = F;
pv->vagon = s;
pv->place = h;
pv->cost = f;
pv->plackart = p;
pv->next = 0;
pv->prev = *pend;
(*pend)->next = pv;
*pend = pv;}
//------------------------------------------------------------------------------
void print (train *const pbeg){
train *pv = pbeg;
while (pv){
cout<<"\tFIO "<<pv->FIO<<"\tVagon:"<<pv->vagon<<"\tPlace:"<<pv->place<<"\tCost:"<<pv->cost<<"\tPlackart:"<<pv->plackart<<endl;
pv = pv ->next;}}
void show (train * const pbeg)
{
train *pv = pbeg;
while (pv)
{
cout<<pv->FIO<<" f.";
cout<<pv->vagon<<" vag.";
cout<<pv->place<<" pl.";
cout<<pv->plackart<<" pc.";
cout<<pv->cost<<endl;
pv=pv->next;
}
cout<<endl;
}
//------------------------------------------------------------------------------
train * find (train * const pbeg, string F){
train *pv = pbeg;
while (pv){
if(pv->FIO == F) break;
pv = pv->next;}
return pv;}
//------------------------------------------------------------------------------
bool remove (train **pbeg, train **pend, string F){
if(train *pkey = find(*pbeg, F)){
if (pkey == *pbeg){
*pbeg = (*pbeg)->next;
(*pbeg)->prev =0;}
else if (pkey == *pend) {
*pend = (*pend)->prev;
(*pend)->next =0;}
else {
(pkey->prev)->next = pkey->next;
(pkey->next)->prev = pkey->prev;}
delete pkey;
return true;}
return false;}
//------------------------------------------------------------------------------
bool set (train * const pbeg, string F, string s, int h, int f, int p){
if (train *pkey = find(pbeg, F)){
pkey->vagon = s;
pkey->place = h;
pkey->cost = f;
pkey->plackart = p;
return true;}
return false;}
//------------------------------------------------------------------------------
int _tmain(int argc, _TCHAR* argv[]){
string F;
string s;
int h;
int f;
int p;
cin>>F; cin>>s; cin>>h; cin>>f; cin>>p;
train *pbeg = first(F,s,h,f,p);
train *pend = pbeg ;
for (int i = 2; i<4; i++) {
cin>>F; cin>>s; cin>>h; cin>>f; cin>>p;
add(&pend,F,s,h,f,p);}
cout<<endl;
print (pbeg);
cout<<endl;
cin>>F;
cout<<endl;
if(!remove (&pbeg, &pend, F)) {cout << "No find!";}
else {cout<<"Dannblu element yspewno ydalen!"<<endl;
print (pbeg);}
cout<<endl;
cin>>F;
cin>>s;
cin>>h;
cin>>f;
cin>>p;
cout<<endl;
if(!set (pbeg,F,s,h,f,p)) {cout << "No find!";}
else {cout<<"Dannblu element yspewno uzmenen!"<<endl;
print (pbeg);}
cout<<endl;
cin>>F;
cin>>s; // Это мой неверный вариант
cin>>h;
cin>>f;
cin>>p;
p = p + f;
cout << "\t Proezd = " << p;
show(pbeg);
system("pause");
return 0;
} |