Advertisement
Guest User

Untitled

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