1565 - I2P18_EECS_Assignment_9 Scoreboard

Time

2018/12/20 16:08:00 2018/12/20 17:17:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10945 Increasing linked list
11751 Sorting makes me happy
11766 NEW Postman

10945 - Increasing linked list   

Description

Given a link list structure named Node.

 

typedef struct _Node {

    int data;

    struct _Node *next;

} Node;

Use this structure to implement a increasing integer link list.

 

You will be provided with main.c and function.h, and asked to implement function.c.

For OJ submission:

       Step 1. Submit only your function.c into the submission block. (Please choose c compiler) 

       Step 2. Check the results and debug your program if necessary.

main.c

function.h

Input

A non negative integer data per rows, if input is smaller then 0 then exit the while loop and exit the program.

Output

Please follow the output of program

Sample Input  Download

Sample Output  Download

Partial Judge Code

10945.c

Partial Judge Header

10945.h

Tags

10502HW1 10502HW 10402HW1 105那個分錯類了...



Discuss




11751 - Sorting makes me happy   

Description

On the Wednesday morning in week 15, TA remembers that HT gives students a homework, which is related to quick sorting with struct.

Now, TA wants to examine that whether you did the homework.

 

We will give you a list of objects, each has three attributes: a int number, a string, and a float number

And you should sort them according to int number first, and then string, and then float number.

(All in the descending order. For example: int number 3 is behind 4 in output list)

(For example: string annie is behind string apple in output list) 

 

HINT: If you don't understand the meaning of the problem after reading above, please see the sample IO and think clearly :) 

 

 

You should implement funcion.c below and submit it. (Due to Partial judge)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "function.h"
 
int compare_function(const void* a, const void* b)
{
 
// set appropriate type
 
// first sorted by value
 
// if equal then soreted by str
 
// if still equal then sorted by x
 
}

 

You should see .c and .h file below to know how the function and the whole program works.

Input

Input will contain four lines.

First line contains N,  indicating the number of objects you should read.

The following three lines contain each object's three attributes: a int number, a string, and a float number.

( 0 < N < 100, 0 < len(string) < 30)

Output

Output contain N lines. (And you should printf "\n" in the end)

You should show the sorted objects in each line in descending order.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11751.c

Partial Judge Header

11751.h

Tags




Discuss




11766 - NEW 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

11766.c

Partial Judge Header

11766.h

Tags




Discuss