JOI2008-2009をC++で解いてみた1問目

#include <iostream>
#include <fstream>
#include <stdlib.h>

using namespace std;

class Man{
    private:
        int m_arrival[3];
        int m_leave[3];
    public:
        Man(string* data_){
            int times[6] = {-1, -1, -1, -1, -1, -1};
            decode(times, data_);
            m_arrival[0] = times[0];
            m_arrival[1] = times[1];
            m_arrival[2] = times[2];
            m_leave[0] = times[3];
            m_leave[1] = times[4];
            m_leave[2] = times[5];
        }
        void decode(int* dest, string* data_){
            string temp("");
            temp.clear();
            string::iterator iter;
            int index = 0;
            data_->append(" ");
            iter = data_->begin();
            for(iter=data_->begin(); iter != data_->end(); iter++){
                if(*iter != ' '){
                    temp.append(&(*iter));
                }else{
                    dest[index] = atoi(temp.c_str());
                    index++;
                    temp.clear();
                }
            }
        }
        void calc(int* dest){
            int arrival = 0;
            int leave = 0;
            int term = 0;
            arrival = (m_arrival[0]*60+m_arrival[1])*60+m_arrival[2];
            leave = (m_leave[0]*60+m_leave[1])*60+m_leave[2];
            term = leave - arrival;
            dest[0] = term / 3600;
            term = term % 3600;
            dest[1] = term / 60;
            term = term % 60;
            dest[2] = term;
        }
};

int main(int argc, char* argv[]){
    int numline = 0;
    Man* men[3];
    int i = 0;
    int term[3];
    ifstream ifs(argv[1]);
    string buf;
    while(getline(ifs, buf)){
        men[i++] = new Man(&buf);
    }
    //out
    ofstream ofs((string(argv[1]) + string("_out.txt")).c_str());
    for(int i=0; i<3; i++){
        men[i]->calc(term);
        cout << term[0] << " " << term[1] << " " << term[2] << endl;
        ofs << term[0] << " " << term[1] << " " << term[2] << endl;
    }
    for(int i=0; i<3; i++){
        delete men[i];
    }
    return 0;
}

(´・ω・)