- import java.io.BufferedInputStream;
- import java.util.Scanner;
- import java.lang.String;
- public class Main {
- public static int time(String a, String b) {// got the D-value of two times
- String tmpa[] = a.split(":");
- String tmpb[] = b.split(":");
- int h1 = Integer.valueOf(tmpa[0]);
- int m1 = Integer.valueOf(tmpa[1]);
- int h2 = Integer.valueOf(tmpb[0]);
- int m2 = Integer.valueOf(tmpb[1]);
- return ((h2 - h1) * 60 + m2 - m1);
- }
- public static void main(String[] args) {
- int numOfCases = 0;// record the num of cases
- int boatNo[] = new int[101];// record the num of boats
- char opOfBoat[] = new char[101];// record the opeator sign of each boats
- String time[] = new String[101];
- Scanner sc = new Scanner(new BufferedInputStream(System.in));
- int chkflag;
- chkflag = sc.nextInt();// if input '-1' then exit
- while (chkflag != -1) {
- boatNo[numOfCases] = chkflag;
- opOfBoat[numOfCases] = sc.next().charAt(0);
- time[numOfCases] = sc.next();
- // if input '0' means is the end of one testcase
- if (boatNo[numOfCases] != 0) {
- numOfCases++;
- } else {// check all data
- if (numOfCases == 0) {
- System.out.println("0 0");
- } else {
- int sumRented = 0; // record the sum num of the boats rented and backed
- int sumTime = 0;
- boolean isDataUsed[] = new boolean[numOfCases];
- for (int i = 0; i < numOfCases; i++) {
- if (isDataUsed[i] || opOfBoat[i] != 'S') {
- // if we have check this data of this is not the data of boat renting,ingore it
- continue;
- } else {
- for (int j = i + 1; j < numOfCases; j++) {
- if (boatNo[j] == boatNo[i] && opOfBoat[j] == 'E') {
- // if we found the first data of the same boat returning then check the time
- sumTime += time(time[i], time[j]);
- sumRented++;
- isDataUsed[i] = true;
- isDataUsed[j] = true;
- break;
- }
- }
- }
- }
- System.out.println(sumRented + " " + (int) Math.rint((double) sumTime / (double) sumRented));
- }
- numOfCases = 0;// reset var
- }
- chkflag = sc.nextInt();
- }
- }
- }
一次AC的水题,纯粹记录一下代码。