Algoogle

Algorithm for Programming Contest

AOJ 2515 Seishun 18 Kippu 2013

Category: AOJ Tag: implementation

Seishun 18 Kippu 2013

問題概要


解法


前の駅の着時刻と現在の駅の出発時刻の差をとればいい

コード


(2515.cpp) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <bits/stdc++.h>
#define rep(i,a) for(int i = 0;i < (a); i++)
#define pb push_back
#define mp make_pair

using namespace std;

int main(){
    int N, T;
    cin >> N >> T;
    vector<pair<string, int> > ans;
    int prev = INF;
    int sh, sm, ah, am;
    string sn, an;
    while(N--){
        scanf("%d:%d",&sh,&sm);
        cin >> sn;
        scanf("%d:%d",&ah,&am);
        cin >> an;
        int m = sh * 60 + sm;
        if(m - prev >= T)ans.pb(mp(sn,m-prev));
        prev = ah * 60 + am;
    }
    cout << ans.size() << endl;
    rep(i,ans.size())
        cout << ans[i].first << ' ' << ans[i].second << endl;
    return 0;
}

Comments