Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <string>
- #include <cmath>
- #include <cstring>
- using namespace std;
- const int MAX_SHIP_COUNT = 1000 ;
- const int MAX_WORK_COUNT = 1000 ;
- class Ship
- {
- protected :
- string shipName ;
- int shipWeight ;
- string danger ;
- public :
- bool whetherDanger ;
- Ship(string shipName , int shipWeight , string danger) ;
- string getshipName() {return shipName;}
- int getshipWeight() {return shipWeight;}
- string getdanger() {return danger;}
- };
- Ship :: Ship(string shipName , int shipWeight , string danger)
- {
- this->shipName = shipName ;
- this->shipWeight = shipWeight ;
- this->danger = danger ;
- };
- class Work
- {
- protected:
- string shipName ;
- int startTime ;
- string type ;
- int first ;
- int second ;
- public :
- bool whetherNight ;
- Work(string shipName , int startTime , string type , int first , int second ) ;
- string getShipName() {return shipName ;}
- int getStartTime(){return startTime ;}
- string getType() {return type ;}
- int getfirst() {return first ;}
- int getsecond() {return second ;}
- };
- Work::Work(string shipName , int startTime , string type , int first , int second )
- {
- this->shipName = shipName ;
- this->startTime = startTime ;
- this->type = type ;
- this->first = first ;
- this->second = second ;
- }
- class In : public Work
- {
- protected :
- public :
- In(string shipName , int startTime , string type , int first , int second) ;
- };
- In::In(string shipName , int startTime , string type , int first , int second) :
- Work(shipName , startTime , type , first , second)
- {
- }
- class Out : public Work
- {
- protected :
- public :
- Out(string shipName , int startTime , string type , int first , int second) ;
- };
- Out::Out(string shipName , int startTime , string type , int first , int second) : Work(shipName , startTime , type , first , second)
- {
- }
- class Trans : public Work
- {
- protected :
- public :
- Trans(string shipName , int startTime , string type , int first , int second) ;
- };
- Trans::Trans(string shipName , int startTime , string type , int first , int second) : Work(shipName , startTime , type , first , second)
- {
- }
- int main()
- {
- int pierNum = 0 ;
- cin >> pierNum ;
- /*int a0 , a1 , a2 , a3 , a4 , b0 , b1 , b2 , b3 , b4 , c0 , c1 , c2 , c3 , c4 , t1 , t2 , t3 ;
- cin >> a0 >> a1 >> a3 >> a4 >> b0 >> b1 >> b2 >> b3 >> b4 >> c0 >> c1 >> c2 >> c3 >> c4 >> t1 >> t2 >> t3 ;*/
- double a0 , a1 , a2 , a3 , a4 , b0 , b1 , b2 , b3 , b4 , c0 , c1 , c2 , c3 , c4 , t1 , t2 , t3 ;
- char input[100] ;
- cin >> input ;
- // seperate by comma
- char *seperate = strtok(input, ",") ;
- a0 = atof(seperate) ;
- seperate = strtok(NULL, ",") ;
- a1 = atof(seperate) ;
- seperate = strtok(NULL, ",") ;
- a2 = atof(seperate) ;
- seperate = strtok(NULL, ",") ;
- a3 = atof(seperate) ;
- seperate = strtok(NULL, ",") ;
- a4 = atof(seperate) ;
- seperate = strtok(NULL, ",") ;
- b0 = atof(seperate) ;
- seperate = strtok(NULL, ",") ;
- b1 = atof(seperate) ;
- seperate = strtok(NULL, ",") ;
- b2 = atof(seperate) ;
- seperate = strtok(NULL, ",") ;
- b3 = atof(seperate) ;
- seperate = strtok(NULL, ",") ;
- b4 = atof(seperate) ;
- seperate = strtok(NULL, ",") ;
- c0 = atof(seperate) ;
- seperate = strtok(NULL, ",") ;
- c1 = atof(seperate) ;
- seperate = strtok(NULL, ",") ;
- c2 = atof(seperate) ;
- seperate = strtok(NULL, ",") ;
- c3 = atof(seperate) ;
- seperate = strtok(NULL, ",") ;
- c4 = atof(seperate) ;
- seperate = strtok(NULL, ",") ;
- t1 = atof(seperate) ;
- seperate = strtok(NULL, ",") ;
- t2 = atof(seperate) ;
- seperate = strtok(NULL, ",") ;
- t3 = atof(seperate) ;
- string shipSample , workSample ;
- cin >> shipSample >> workSample ;
- string weight ;
- int shipWeight = 0 ;
- string country ;
- string captainName ;
- string danger ;
- string shipName ;
- string start ;
- int startTime = 0 ;
- string type ;
- string fir ;
- int first ;
- string sec ;
- int second ;
- // 使用Work型類別的指標儲存資料
- Ship** shippingData = new Ship*[MAX_SHIP_COUNT] ;
- Work** workingData = new Work*[MAX_WORK_COUNT] ;
- int shipNum = 0 ;
- int workNum = 0 ;
- int inNum = 0 ;
- int outNum = 0 ;
- int transNum = 0 ;
- int badDataCount = 0 ;
- int answer[1000] = {0} ;
- ifstream shipData(shipSample) ;
- {
- while(!shipData.eof())
- {
- getline(shipData , shipName , ',') ;
- getline(shipData , weight , ',') ;
- shipWeight = atoi(weight.c_str() ) ;
- getline(shipData , country , ',') ;
- getline(shipData , captainName , ',') ;
- shipData >> danger ;
- shipData.ignore() ;
- // cout << shipName << " " << shipWeight << " " << country << " " << captainName << " " << danger << endl ;
- shipNum++ ;
- shippingData[shipNum] = new Ship(shipName , shipWeight , danger) ;
- }
- }
- ifstream workData(workSample) ;
- {
- while(!workData.eof())
- {
- getline(workData , shipName , ',') ;
- if(shipName == "")
- {
- answer[workNum] = -1 ;
- workNum++ ;
- badDataCount++ ;
- continue ;
- }
- getline(workData , start , ',') ;
- if(start == "")
- {
- answer[workNum] = -1 ;
- workNum++ ;
- badDataCount++ ;
- continue ;
- }
- else
- {
- startTime = 600 * (start[0] - 48) + 60 * (start[1] - 48) + 10 * (start[3] - 48) + (start[4] - 48);
- }
- getline(workData , type , ',') ;
- if(type == "")
- {
- answer[workNum] = -1 ;
- workNum++ ;
- badDataCount++ ;
- continue ;
- }
- getline(workData , fir , ',') ;
- if(fir == "")
- {
- answer[workNum] = -1 ;
- workNum++ ;
- badDataCount++ ;
- continue ;
- }
- else
- first = atoi(fir.c_str() ) ;
- workData >> sec ;
- workData.ignore() ;
- if(sec == "")
- {
- answer[workNum] = -1 ;
- workNum++ ;
- badDataCount++ ;
- continue ;
- }
- else
- second = atoi(sec.c_str() ) ;
- // cout << shipName << " " << startTime << " " << type << " " << first << " " << second << endl ;
- if(answer[workNum] != -1)
- {
- workingData[workNum] = new Work(shipName , startTime , type , first , second) ;
- workNum++ ;
- if(type == "I")
- inNum++ ;
- else if(type == "O")
- outNum++ ;
- else if(type == "T")
- transNum++ ;
- }
- }
- }
- for(int i = 0 ; i < shipNum ; i++)
- {
- if(shippingData[i]->getdanger() == "Y")
- shippingData[i]->whetherDanger = 1 ;
- else if(shippingData[i]->getdanger() == "N")
- shippingData[i]->whetherDanger = 0 ;
- }
- for(int i = 0 ; i < workNum ; i++)
- {
- if(workingData[i]->getStartTime() <= 360 || workingData[i]->getStartTime() >= 1080)
- workingData[i]->whetherNight = 1 ;
- else if(workingData[i]->getStartTime() > 360 && workingData[i]->getStartTime() < 1080)
- workingData[i]->whetherNight = 0 ;
- }
- for(int i = 0 ; i < shipNum ; i++)
- {
- for(int j = 0 ; j < workNum ; j++)
- {
- if(shippingData[i]->getshipName() == workingData[j]->getShipName())
- {
- if(answer[j] != -1)
- {
- if(workingData[j]->getType() == "I")
- {
- if(workingData[j]->getsecond() % 2 == 0)
- answer[j] = a0 + a1*(t1 + t3 + t2*(workingData[j]->getsecond() / 2)) + a2*shippingData[i]->getshipWeight() + a3*shippingData[i]->whetherDanger + a4*workingData[j]->whetherNight ;
- else if(workingData[j]->getsecond() % 2 == 1)
- answer[j] = a0 + a1*(t1 + t3*((workingData[j]->getsecond() / 2) + 1)) + a2*shippingData[i]->getshipWeight() + a3*shippingData[i]->whetherDanger + a4*workingData[j]->whetherNight ;
- }
- else if(workingData[j]->getType() == "O")
- {
- if(workingData[j]->getsecond() % 2 == 0)
- answer[j] = b0 + b1*(t1 + t3 + t2*(workingData[j]->getsecond() / 2)) + b2*shippingData[i]->getshipWeight() + b3*shippingData[i]->whetherDanger + b4*workingData[j]->whetherNight ;
- else if(workingData[j]->getsecond() % 2 == 1)
- answer[j] = b0 + b1*(t1 + t3*((workingData[j]->getsecond() / 2) + 1)) + b2*shippingData[i]->getshipWeight() + b3*shippingData[i]->whetherDanger + b4*workingData[j]->whetherNight ;
- }
- else if(workingData[j]->getType() == "T")
- {
- if(workingData[j]->getfirst() % 2 == 0 && workingData[j]->getsecond() % 2 == 0 )
- 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 ;
- else if(workingData[j]->getfirst() % 2 == 1 && workingData[j]->getsecond() % 2 == 1)
- 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 ;
- else if(workingData[j]->getfirst() % 2 == 0 && workingData[j]->getsecond() % 2 == 1)
- {
- if(workingData[j]->getfirst() > workingData[j]->getsecond())
- 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 ;
- else if(workingData[j]->getfirst() < workingData[j]->getsecond())
- 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 ;
- }
- else if(workingData[j]->getfirst() % 2 == 1 && workingData[j]->getsecond() % 2 == 0)
- {
- if(workingData[j]->getfirst() > workingData[j]->getsecond())
- 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 ;
- else if(workingData[j]->getfirst() < workingData[j]->getsecond())
- 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 ;
- }
- }
- }
- }
- }
- }
- for(int i = 0 ; i < workNum - 1 ; i++)
- cout << answer[workNum] << "," ;
- cout << answer[workNum - 1] << endl ;
- cout << badDataCount ;
- return 0 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement