24h購物| | PChome| 登入
2013-02-23 09:02:43| 人氣620| 回應0 | 上一篇 | 下一篇

[UVA][strcasecmp] 11056 - Formula 1

推薦 0 收藏 0 轉貼0 訂閱站台

Problem A – Formula 1

Time Limit: 1 second

It’s time for a new Formula 1 race and the board of directors decided that it’s also time for a new chronometer system. They bought all the ultra-modern radar-laser-microwave sensors to install in the starting line, but just realized the manufacturer didn’t provide the software to rank the cars.

That’s how you come to the game. The board of directors wants you to write a program that receives the time each pilot spent on their qualification lap and prints the starting grid for the race (i.e. the order in which the pilots must start the race). And they want it fast! I bet you can do it in the time of a pit stop!

(If you don’t know the rules that make the starting grid in Formula 1, consider that the least time the pilot spend on the qualification lap the best, i.e. the closest he will start of the beginning of the grid).

Input

The input file contains several input sets. The description of each set is given below:

Each set starts with one integer N (1 ≤ N ≤ 100), the number of participant pilots in the race, on the first line.

Then, N lines in the format “S : X min Y sec Z ms” will follow (quotes for clarity only). The value S represents the name of the pilot and consists of a string of 1 to 20 letters. The integers X (0 ≤ C ≤ 59), Y (0 ≤ C ≤ 59) and Z (0 ≤ C ≤ 999) represent the number of minutes, seconds and milliseconds, respectively, that the pilot spent on his qualification lap.

There is a blank line after each input set. Input is terminated by EOF.

Output

For each input set, your program must produce the starting grid, i.e. the order in which the pilots must start the race, in the following format. For each row in the grid (a pair of cars that start the race side by side), print a line containing “Row R”, where R represents the row number starting from 1, followed by two other lines containing the name of the pilots (as appear in the input) that start the race from that row (in order of classification). If one row contains only one pilot, just print one line after the row number. If there are two pilots with the same name on a test case, they are different pilots and the output must contain both pilots. If two or more pilots are tied in the classification time, sort them by their names (lexicographically, case-insensitive comparisons). Print a blank line after each test case.

Sample Input

3

Schumacher : 1 min 23 sec 172 ms

Barrichello : 2 min 12 sec 999 ms

Senna : 0 min 55 sec 582 ms

 

4

Schumacher : 1 min 23 sec 172 ms

Barrichello : 2 min 12 sec 999 ms

Senna : 0 min 55 sec 582 ms

Fangio : 1 min 03 sec 000 ms

 

2

BadPilot : 59 min 59 sec 999 ms

ABadPilot : 59 min 59 sec 999 ms

Sample Output

Row 1

Senna

Schumacher

Row 2

Barrichello

 

Row 1

Senna

Fangio

Row 2

Schumacher

Barrichello

 

Row 1

ABadPilot

BadPilot

 


Problem setter: Herbert de Mélo Duarte

依照時間排序,如果時間一樣比較選手名字,此時忽略大小寫的字典順序。

之後兩兩分一組。

使用 strcasecmp 去比較。


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
char name[105][150];
int time[105], IDX[105];
bool cmp(int a, int b) {
    if(time[a] != time[b])
        return time[a] < time[b];
    return strcasecmp(name[a], name[b]) < 0;
}
int main() {
    int n, i, j;
    int mm, ss, mss;
    while(scanf("%d", &n) == 1) {
        for(i = 0; i < n; i++) {
            scanf("%s : %d min %d sec %d ms", &name[i], &mm, &ss, &mss);
            time[i] = mss + ss*1000 + mm*60000;
            IDX[i] = i;
        }
        sort(IDX, IDX+n, cmp);
        for(i = 0, j = 1; i < n; i += 2, j++) {
            printf("Row %d\n", j);
            puts(name[IDX[i]]);
            if(i+1 < n)
                puts(name[IDX[i+1]]);
        }
        puts("");
    }
    return 0;
}

台長: Morris
人氣(620) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][RGB] 10823 - Of Circles and Squares
此分類上一篇:[UVA][凸包關係、射線法、線段交] 10256 - The Great Divide

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文