904 - I2P(I)2015_Yang_Lab_13 Scoreboard

Time

2016/01/07 13:25:00 2016/01/07 15:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10903 Postman

10903 - Postman   

Description

Collected letters would be classified by zip code. After that, certain postman likes to sort the letters by sender’s name. Here’s an example:

30013 Xiao                10850 Wang

23679 Huang             23679 Huang

24241 Chen      ->      24241 Chen

89346 Hsu                 30013 Tsai                  

10850 Wang              30013 Xiao            

30013 Tsai                 89346 Hsu

Letters would be arranged firstly by zip code, secondly by name once zip codes are the same. Sort the letters with the name by the weight of the string from high to low. The weight of string is defined as following: 

Lower case letters: a ~ z corresponds to 1 ~ 26

Upper case letters: A ~ Z corresponds to 2 ~ 27

letter a b c d e f g h i j k l m n o p q r s t u v w x y z
weight 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
letter A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
weight 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

For example, the weight of "Allen" is 2 + 12 + 12 + 5 + 14 = 45

Once the zip code and the weight are the same. Dictionary order is used for sorting names. As an example, the weight of “Tsai” and “Xiao” are the same, “T” is previous than “X”, which results the order: 30013 Tsai, 30013 Xiao.
 

main.c

#include <stdio.h>
#include <stdlib.h>
#include "function.h"

int main(void){

     int n;
     int i;
     Letter *letters;

     // Read inputs
     scanf("%d", &n);
     letters = (Letter*)malloc(sizeof(Letter)*n);
     for(i=0; i<n; i++)
          scanf("%d %s", &(letters[i].zipcode), letters[i].name);

     // Sort the data
     qsort((void*)letters, n, sizeof(Letter), compare);

     // Output result
     for(i=0; i<n; i++)
          printf("%d %s\n", letters[i].zipcode, letters[i].name);

     free(letters);

     return 0;
}

function.h

#ifndef FUNCTION_H
#define FUNCTION_H

typedef struct {
  int zipcode;
  char name[15];
} Letter;

int compare(const void *, const void *);

#endif

Input

First line is an integer N, number of the letters. The following N lines have an integer, zip code, followed by a name. N is less than 10 million.

Output

Sorted result, N lines, each line contains the zip code and a name separated by a space.

Sample Input  Download

Sample Output  Download

Partial Judge Code

10903.c

Partial Judge Header

10903.h

Tags

contest 10401Contest



Discuss