Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <string>
  5. #include <cmath>
  6. #include <cstring>
  7. using namespace std;
  8.  
  9. const int MAX_SHIP_COUNT = 1000 ;
  10. const int MAX_WORK_COUNT = 1000 ;
  11.  
  12. class Ship
  13. {
  14. protected :
  15. string shipName ;
  16. int shipWeight ;
  17. bool danger ;
  18. public :
  19. Ship(string shipName , int shipWeight , bool danger) ;
  20. virtual string getshipName() {return shipName;}
  21. virtual int getshipWeight() {return shipWeight;}
  22. virtual bool getdanger() {return danger;}
  23. };
  24.  
  25. Ship :: Ship(string shipName , int shipWeight , bool danger)
  26. {
  27. this->shipName = shipName ;
  28. this->shipWeight = shipWeight ;
  29. this->danger = danger ;
  30. };
  31.  
  32. class Work
  33. {
  34. protected:
  35. string shipName ;
  36. int startTime ;
  37. string type ;
  38. int first ;
  39. int second ;
  40. bool night ;
  41. Ship* ship ;
  42. public :
  43.  
  44. Work(string shipName , bool night , string type , int first , int second ) ;
  45. virtual string getShipName() {return shipName ;}
  46. virtual bool getnight() {return night ;}
  47. virtual string getType() {return type ;}
  48. virtual int getfirst() {return first ;}
  49. virtual int getsecond() {return second ;}
  50. Ship* getship() {return ship ;}
  51. void linked(Ship* ship){this->ship = ship ;}
  52.  
  53.  
  54.  
  55. };
  56.  
  57. Work::Work(string shipName , bool night , string type , int first , int second )
  58. {
  59. this->shipName = shipName ;
  60. this->night = night ;
  61. this->type = type ;
  62. this->first = first ;
  63. this->second = second ;
  64. }
  65.  
  66. class In : public Work
  67. {
  68. protected :
  69. public :
  70. In(string shipName , bool night , string type , int first , int second) ;
  71. };
  72.  
  73. In::In(string shipName , bool night , string type , int first , int second) :
  74. Work(shipName , night , type , first , second)
  75. {
  76. }
  77.  
  78. class Out : public Work
  79. {
  80. protected :
  81. public :
  82. Out(string shipName , bool night , string type , int first , int second) ;
  83. };
  84.  
  85. Out::Out(string shipName , bool night , string type , int first , int second) : Work(shipName , night , type , first , second)
  86. {
  87. }
  88.  
  89. class Trans : public Work
  90. {
  91. protected :
  92. public :
  93. Trans(string shipName , bool night , string type , int first , int second) ;
  94. };
  95.  
  96. Trans::Trans(string shipName , bool night , string type , int first , int second) : Work(shipName , night , type , first , second)
  97. {
  98. }
  99.  
  100.  
  101.  
  102. int main()
  103. {
  104. int pierNum = 0 ;
  105. cin >> pierNum ;
  106.  
  107. /*int a0 , a1 , a2 , a3 , a4 , b0 , b1 , b2 , b3 , b4 , c0 , c1 , c2 , c3 , c4 , t1 , t2 , t3 ;
  108. cin >> a0 >> a1 >> a3 >> a4 >> b0 >> b1 >> b2 >> b3 >> b4 >> c0 >> c1 >> c2 >> c3 >> c4 >> t1 >> t2 >> t3 ;*/
  109.  
  110. double a0 , a1 , a2 , a3 , a4 , b0 , b1 , b2 , b3 , b4 , c0 , c1 , c2 , c3 , c4 , t1 , t2 , t3 ;
  111.  
  112. char input[100] ;
  113. cin >> input ;
  114.  
  115. // seperate by comma
  116. char *seperate = strtok(input, ",") ;
  117. a0 = atof(seperate) ;
  118. seperate = strtok(NULL, ",") ;
  119. a1 = atof(seperate) ;
  120. seperate = strtok(NULL, ",") ;
  121. a2 = atof(seperate) ;
  122. seperate = strtok(NULL, ",") ;
  123. a3 = atof(seperate) ;
  124. seperate = strtok(NULL, ",") ;
  125. a4 = atof(seperate) ;
  126. seperate = strtok(NULL, ",") ;
  127. b0 = atof(seperate) ;
  128. seperate = strtok(NULL, ",") ;
  129. b1 = atof(seperate) ;
  130. seperate = strtok(NULL, ",") ;
  131. b2 = atof(seperate) ;
  132. seperate = strtok(NULL, ",") ;
  133. b3 = atof(seperate) ;
  134. seperate = strtok(NULL, ",") ;
  135. b4 = atof(seperate) ;
  136. seperate = strtok(NULL, ",") ;
  137. c0 = atof(seperate) ;
  138. seperate = strtok(NULL, ",") ;
  139. c1 = atof(seperate) ;
  140. seperate = strtok(NULL, ",") ;
  141. c2 = atof(seperate) ;
  142. seperate = strtok(NULL, ",") ;
  143. c3 = atof(seperate) ;
  144. seperate = strtok(NULL, ",") ;
  145. c4 = atof(seperate) ;
  146. seperate = strtok(NULL, ",") ;
  147. t1 = atof(seperate) ;
  148. seperate = strtok(NULL, ",") ;
  149. t2 = atof(seperate) ;
  150. seperate = strtok(NULL, ",") ;
  151. t3 = atof(seperate) ;
  152.  
  153. // cout << a0 << " " << a1 << " " << a2 << " " << a3 << " " << a4 << " " << b0 << " " << b1 << " " << b2 << " " << b3 << " " << b4 << " " << c0 << " " << c1 << " " << c2 << " " << c3 << " " << c4 << " " << t1 << " " << t2 << " " << t3 ;
  154.  
  155. string shipSample , workSample ;
  156. cin >> shipSample >> workSample ;
  157.  
  158. string weight ;
  159. int shipWeight = 0 ;
  160. string country ;
  161. string captainName ;
  162. string Danger ;
  163. bool danger = false ;
  164.  
  165. string shipName ;
  166. string start ;
  167. int startTime = 0 ;
  168. bool night = false ;
  169. string type ;
  170. string fir ;
  171. int first = 0 ;
  172. string sec ;
  173. int second = 0 ;
  174.  
  175. Ship** shippingData = new Ship*[MAX_SHIP_COUNT] ;
  176. Work** workingData = new Work*[MAX_WORK_COUNT] ;
  177.  
  178. int shipNum = 0 ;
  179. int workNum = -1 ;
  180. int inNum = 0 ;
  181. int outNum = 0 ;
  182. int transNum = 0 ;
  183.  
  184. int badDataCount = 0 ;
  185.  
  186. int answer[1000] = {0} ;
  187.  
  188. ifstream shipData(shipSample) ;
  189. {
  190. while(!shipData.eof())
  191. {
  192. getline(shipData , shipName , ',') ;
  193.  
  194. getline(shipData , weight , ',') ;
  195. shipWeight = atoi(weight.c_str() ) ;
  196.  
  197. getline(shipData , country , ',') ;
  198.  
  199. getline(shipData , captainName , ',') ;
  200.  
  201. shipData >> Danger ;
  202. shipData.ignore() ;
  203. if(Danger == "Y")
  204. danger = 1 ;
  205. else if(Danger == "N")
  206. danger = 0 ;
  207.  
  208.  
  209. // cout << shipName << " " << shipWeight << " " << country << " " << captainName << " " << danger << endl ;
  210.  
  211.  
  212. shippingData[shipNum] = new Ship(shipName , shipWeight , danger) ;
  213. shipNum++ ;
  214. }
  215. }
  216.  
  217. ifstream workData(workSample) ;
  218. {
  219. while(!workData.eof())
  220. {
  221. workNum++ ;
  222. getline(workData , shipName , ',') ;
  223. if(shipName.size() == 0)
  224. {
  225. cout << "bad " ;
  226. answer[workNum] = -1 ;
  227. badDataCount++ ;
  228. continue ;
  229. }
  230.  
  231. getline(workData , start , ',') ;
  232. if(start.size() == 0)
  233. {
  234. cout << "bad " ;
  235. answer[workNum] = -1 ;
  236. badDataCount++ ;
  237. continue ;
  238. }
  239.  
  240. else if(start.size() != 0)
  241. {
  242. startTime = 600 * (start[0] - 48) + 60 * (start[1] - 48) + 10 * (start[3] - 48) + (start[4] - 48) ;
  243. }
  244.  
  245. if(startTime <= 360 || startTime >= 1080)
  246. night = 1 ;
  247.  
  248. else if(startTime > 360 && startTime < 1080)
  249. night = 0 ;
  250.  
  251. getline(workData , type , ',') ;
  252. if(type.size() == 0)
  253. {
  254. cout << "bad " ;
  255. answer[workNum] = -1 ;
  256. badDataCount++ ;
  257. continue ;
  258. }
  259.  
  260. getline(workData , fir , ',') ;
  261. if(fir.size() == 0)
  262. {
  263. cout << "bad " ;
  264. answer[workNum] = -1 ;
  265. badDataCount++ ;
  266. continue ;
  267. }
  268. else if(fir.size() != 0)
  269. first = atoi(fir.c_str() ) ;
  270.  
  271. workData >> sec ;
  272. workData.ignore() ;
  273. if(sec.size() == 0)
  274. {
  275. cout << "bad " ;
  276. answer[workNum] = -1 ;
  277. badDataCount++ ;
  278. continue ;
  279. }
  280. else if(sec.size() != 0)
  281. second = atoi(sec.c_str() ) ;
  282.  
  283. if(answer[workNum] != -1)
  284. {
  285. cout << shipName << " " << startTime << " " << type << " " << first << " " << second << endl ;
  286.  
  287. workingData[workNum] = new Work(shipName , night , type , first , second) ;
  288. workNum++ ;
  289.  
  290. if(type == "I")
  291. inNum++ ;
  292. else if(type == "O")
  293. outNum++ ;
  294. else if(type == "T")
  295. transNum++ ;
  296. }
  297.  
  298.  
  299. }
  300. }
  301.  
  302. // for(int i = 0 ; i < workNum ; i++)
  303. // cout << workingData[i]->getShipName() << endl ;
  304.  
  305. // for(int i = 0 ; i < shipNum ; i++)
  306. // cout << shippingData[i]->getshipName() << " " << shippingData[i]->getshipWeight() << " " << shippingData[i]->getdanger() << endl ;
  307.  
  308. for(int i = 0 ; i < workNum ; i++)
  309. {
  310. for(int j = 0 ; j < shipNum ; j++)
  311. {
  312. if(workingData[i]->getShipName() == shippingData[j]->getshipName())
  313. {
  314. workingData[i]->linked(shippingData[j]) ;
  315. break ;
  316. }
  317. }
  318. }
  319.  
  320.  
  321.  
  322. for(int j = 0 ; j < workNum ; j++)
  323. {
  324. if(answer[j] != -1)
  325. {
  326. if(workingData[j]->getType() == "I")
  327. {
  328. if(workingData[j]->getsecond() % 2 == 0)
  329. answer[j] = a0 + a1*(t1 + t3 + t2*(workingData[j]->getsecond() / 2)) + a2*workingData[j]->getship()->getshipWeight() + a3*workingData[j]->getship()->getdanger() + a4*workingData[j]->getnight() ;
  330. else if(workingData[j]->getsecond() % 2 == 1)
  331. answer[j] = a0 + a1*(t1 + t3*((workingData[j]->getsecond() / 2) + 1)) + a2*workingData[j]->getship()->getshipWeight() + a3*workingData[j]->getship()->getdanger() + a4*workingData[j]->getnight() ;
  332. }
  333.  
  334. else if(workingData[j]->getType() == "O")
  335. {
  336. if(workingData[j]->getsecond() % 2 == 0)
  337. answer[j] = b0 + b1*(t1 + t3 + t2*(workingData[j]->getsecond() / 2)) + b2*workingData[j]->getship()->getshipWeight() + b3*workingData[j]->getship()->getdanger() + b4*workingData[j]->getnight() ;
  338. else if(workingData[j]->getsecond() % 2 == 1)
  339. answer[j] = b0 + b1*(t1 + t3*((workingData[j]->getsecond() / 2) + 1)) + b2*workingData[j]->getship()->getshipWeight() + b3*workingData[j]->getship()->getdanger() + b4*workingData[j]->getnight() ;
  340. }
  341.  
  342. else if(workingData[j]->getType() == "T")
  343. {
  344. if(workingData[j]->getfirst() % 2 == 0 && workingData[j]->getsecond() % 2 == 0 )
  345.  
  346. answer[j] = c0 + c1*t2*(abs((workingData[j]->getsecond() - workingData[j]->getfirst()) / 2)) + c2*workingData[j]->getship()->getshipWeight() + c3*workingData[j]->getship()->getdanger() + c4*workingData[j]->getnight() ;
  347.  
  348. else if(workingData[j]->getfirst() % 2 == 1 && workingData[j]->getsecond() % 2 == 1)
  349.  
  350. answer[j] = c0 + c1*t2*(abs((workingData[j]->getsecond() - workingData[j]->getfirst()) / 2)) + c2*workingData[j]->getship()->getshipWeight() + c3*workingData[j]->getship()->getdanger() + c4*workingData[j]->getnight() ;
  351.  
  352. else if(workingData[j]->getfirst() % 2 == 0 && workingData[j]->getsecond() % 2 == 1)
  353. {
  354. if(workingData[j]->getfirst() > workingData[j]->getsecond())
  355.  
  356. answer[j] = c0 + c1*(t3 + t2*(abs((workingData[j]->getfirst() - 1 - workingData[j]->getsecond())/ 2))) + c2*workingData[j]->getship()->getshipWeight() + c3*workingData[j]->getship()->getdanger() + c4*workingData[j]->getnight() ;
  357.  
  358. else if(workingData[j]->getfirst() < workingData[j]->getsecond())
  359. answer[j] = c0 + c1*(t3 + t2*(abs((workingData[j]->getsecond() + 1 - workingData[j]->getfirst())/ 2))) + c2*workingData[j]->getship()->getshipWeight() + c3*workingData[j]->getship()->getdanger() + c4*workingData[j]->getnight() ;
  360.  
  361. }
  362.  
  363. else if(workingData[j]->getfirst() % 2 == 1 && workingData[j]->getsecond() % 2 == 0)
  364. {
  365. if(workingData[j]->getfirst() > workingData[j]->getsecond())
  366.  
  367. answer[j] = c0 + c1*(t3 + t2*(abs((workingData[j]->getfirst() + 1 - workingData[j]->getsecond())/ 2))) + c2*workingData[j]->getship()->getshipWeight() + c3*workingData[j]->getship()->getdanger() + c4*workingData[j]->getnight() ;
  368.  
  369. else if(workingData[j]->getfirst() < workingData[j]->getsecond())
  370. answer[j] = c0 + c1*(t3 + t2*(abs((workingData[j]->getsecond() - 1 - workingData[j]->getfirst())/ 2))) + c2*workingData[j]->getship()->getshipWeight() + c3*workingData[j]->getship()->getdanger() + c4*workingData[j]->getnight() ;
  371. }
  372.  
  373. }
  374. }
  375.  
  376. // else
  377. // break ;
  378. }
  379.  
  380.  
  381. for(int i = 0 ; i < workNum - 1 ; i++)
  382. cout << answer[workNum] << "," ;
  383. cout << answer[workNum - 1] << endl ;
  384.  
  385. cout << badDataCount ;
  386.  
  387.  
  388.  
  389.  
  390. return 0 ;
  391. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement