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 ;
- bool danger ;
- public :
- Ship(string shipName , int shipWeight , bool danger) ;
- virtual string getshipName() {return shipName;}
- virtual int getshipWeight() {return shipWeight;}
- virtual bool getdanger() {return danger;}
- };
- Ship :: Ship(string shipName , int shipWeight , bool danger)
- {
- this->shipName = shipName ;
- this->shipWeight = shipWeight ;
- this->danger = danger ;
- };
- class Work
- {
- protected:
- string shipName ;
- int startTime ;
- string type ;
- int first ;
- int second ;
- bool night ;
- Ship* ship ;
- public :
- Work(string shipName , bool night , string type , int first , int second ) ;
- virtual string getShipName() {return shipName ;}
- virtual bool getnight() {return night ;}
- virtual string getType() {return type ;}
- virtual int getfirst() {return first ;}
- virtual int getsecond() {return second ;}
- Ship* getship() {return ship ;}
- void linked(Ship* ship){this->ship = ship ;}
- };
- Work::Work(string shipName , bool night , string type , int first , int second )
- {
- this->shipName = shipName ;
- this->night = night ;
- this->type = type ;
- this->first = first ;
- this->second = second ;
- }
- class In : public Work
- {
- protected :
- public :
- In(string shipName , bool night , string type , int first , int second) ;
- };
- In::In(string shipName , bool night , string type , int first , int second) :
- Work(shipName , night , type , first , second)
- {
- }
- class Out : public Work
- {
- protected :
- public :
- Out(string shipName , bool night , string type , int first , int second) ;
- };
- Out::Out(string shipName , bool night , string type , int first , int second) : Work(shipName , night , type , first , second)
- {
- }
- class Trans : public Work
- {
- protected :
- public :
- Trans(string shipName , bool night , string type , int first , int second) ;
- };
- Trans::Trans(string shipName , bool night , string type , int first , int second) : Work(shipName , night , 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) ;
- // cout << a0 << " " << a1 << " " << a2 << " " << a3 << " " << a4 << " " << b0 << " " << b1 << " " << b2 << " " << b3 << " " << b4 << " " << c0 << " " << c1 << " " << c2 << " " << c3 << " " << c4 << " " << t1 << " " << t2 << " " << t3 ;
- string shipSample , workSample ;
- cin >> shipSample >> workSample ;
- string weight ;
- int shipWeight = 0 ;
- string country ;
- string captainName ;
- string Danger ;
- bool danger = false ;
- string shipName ;
- string start ;
- int startTime = 0 ;
- bool night = false ;
- string type ;
- string fir ;
- int first = 0 ;
- string sec ;
- int second = 0 ;
- Ship** shippingData = new Ship*[MAX_SHIP_COUNT] ;
- Work** workingData = new Work*[MAX_WORK_COUNT] ;
- int shipNum = 0 ;
- int workNum = -1 ;
- 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() ;
- if(Danger == "Y")
- danger = 1 ;
- else if(Danger == "N")
- danger = 0 ;
- // cout << shipName << " " << shipWeight << " " << country << " " << captainName << " " << danger << endl ;
- shippingData[shipNum] = new Ship(shipName , shipWeight , danger) ;
- shipNum++ ;
- }
- }
- ifstream workData(workSample) ;
- {
- while(!workData.eof())
- {
- workNum++ ;
- getline(workData , shipName , ',') ;
- if(shipName.size() == 0)
- {
- cout << "bad " ;
- answer[workNum] = -1 ;
- badDataCount++ ;
- continue ;
- }
- getline(workData , start , ',') ;
- if(start.size() == 0)
- {
- cout << "bad " ;
- answer[workNum] = -1 ;
- badDataCount++ ;
- continue ;
- }
- else if(start.size() != 0)
- {
- startTime = 600 * (start[0] - 48) + 60 * (start[1] - 48) + 10 * (start[3] - 48) + (start[4] - 48) ;
- }
- if(startTime <= 360 || startTime >= 1080)
- night = 1 ;
- else if(startTime > 360 && startTime < 1080)
- night = 0 ;
- getline(workData , type , ',') ;
- if(type.size() == 0)
- {
- cout << "bad " ;
- answer[workNum] = -1 ;
- badDataCount++ ;
- continue ;
- }
- getline(workData , fir , ',') ;
- if(fir.size() == 0)
- {
- cout << "bad " ;
- answer[workNum] = -1 ;
- badDataCount++ ;
- continue ;
- }
- else if(fir.size() != 0)
- first = atoi(fir.c_str() ) ;
- workData >> sec ;
- workData.ignore() ;
- if(sec.size() == 0)
- {
- cout << "bad " ;
- answer[workNum] = -1 ;
- badDataCount++ ;
- continue ;
- }
- else if(sec.size() != 0)
- second = atoi(sec.c_str() ) ;
- if(answer[workNum] != -1)
- {
- cout << shipName << " " << startTime << " " << type << " " << first << " " << second << endl ;
- workingData[workNum] = new Work(shipName , night , type , first , second) ;
- workNum++ ;
- if(type == "I")
- inNum++ ;
- else if(type == "O")
- outNum++ ;
- else if(type == "T")
- transNum++ ;
- }
- }
- }
- // for(int i = 0 ; i < workNum ; i++)
- // cout << workingData[i]->getShipName() << endl ;
- // for(int i = 0 ; i < shipNum ; i++)
- // cout << shippingData[i]->getshipName() << " " << shippingData[i]->getshipWeight() << " " << shippingData[i]->getdanger() << endl ;
- for(int i = 0 ; i < workNum ; i++)
- {
- for(int j = 0 ; j < shipNum ; j++)
- {
- if(workingData[i]->getShipName() == shippingData[j]->getshipName())
- {
- workingData[i]->linked(shippingData[j]) ;
- break ;
- }
- }
- }
- for(int j = 0 ; j < workNum ; j++)
- {
- 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*workingData[j]->getship()->getshipWeight() + a3*workingData[j]->getship()->getdanger() + a4*workingData[j]->getnight() ;
- else if(workingData[j]->getsecond() % 2 == 1)
- 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() ;
- }
- else if(workingData[j]->getType() == "O")
- {
- if(workingData[j]->getsecond() % 2 == 0)
- 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() ;
- else if(workingData[j]->getsecond() % 2 == 1)
- 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() ;
- }
- 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*workingData[j]->getship()->getshipWeight() + c3*workingData[j]->getship()->getdanger() + c4*workingData[j]->getnight() ;
- 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*workingData[j]->getship()->getshipWeight() + c3*workingData[j]->getship()->getdanger() + c4*workingData[j]->getnight() ;
- 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*workingData[j]->getship()->getshipWeight() + c3*workingData[j]->getship()->getdanger() + c4*workingData[j]->getnight() ;
- else if(workingData[j]->getfirst() < workingData[j]->getsecond())
- 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() ;
- }
- 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*workingData[j]->getship()->getshipWeight() + c3*workingData[j]->getship()->getdanger() + c4*workingData[j]->getnight() ;
- else if(workingData[j]->getfirst() < workingData[j]->getsecond())
- 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() ;
- }
- }
- }
- // else
- // break ;
- }
- 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