2013年8月21日

UVa 11056 - Formula 1

#include <cstdio>
#include <cctype>
#include <string>
#include <vector>
#include <algorithm>
#define PB push_back
using namespace std;

string lower(string s) {
  string ls = s;
  for (int i = 0; ls[i]; i++) {
    ls[i] = tolower(ls[i]);
  }
  return ls;
}

struct Person {
  Person(char * name, int time) : name(name), time(time) {
    lname = lower(name);
  }
  bool operator < (const Person & other) const {
    return (time != other.time) ? (time < other.time) : (lname < other.lname);
  }
  string name, lname;
  int time;
};

int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    vector<Person> people;
    for (int i = 0; i < n; i++) {
      char name[99], t[99];
      int m, s, ms;
      scanf("%s%s%d%s%d%s%d%s", name, t, &m, t, &s, t, &ms, t);
      people.PB(Person(name, (m * 60 + s) * 1000 + ms));
    }
    sort(people.begin(), people.end());
    for (int i = 0, R = 1; i < n; i += 2, R++) {
      printf("Row %d\n", R);
      puts(people[i].name.c_str());
      if (i + 1 < n) {
        puts(people[i + 1].name.c_str());
      }
    }
    puts("");
  }
  return 0;
}

沒有留言:

張貼留言