3273 - EE2310 Week 11 Practice Scoreboard

Time

2025/11/17 12:00:00 2025/12/31 23:59:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
14834 Binary file comparison
14835 Friendship
14836 Reverse output of linked sequence data

14834 - Binary file comparison   

Description

Write a program to compare two binary files.
The comparison method is to compare one byte at a time and list all the places where they differ.
The input consists of two lines, each containing the filename of one file. The maximum filename length is n.
The output should be the positions (offsets) where the two files differ.
If the two files are of different sizes, you must first output the name of the larger file, then output the extra bytes.

Parameter specification: 0 < n ≤ 80

Input

Consists of two lines, each containing the filename of one file.

The maximum filename length is n.

Ex. leap-year.c
leap-year-mod.c

leap-year.c

#include <stdio.h>
main()
{
    int year;
    int k;
    scanf("%d", &year);
    k = (year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0));
    printf("%d\n", k);
}

leap-year-mod.c

%include <stdio.h>
maim()
{
    int year;
    int k;
    scanf("%d", &year);
    k = (year % 500 == 0) || ((year % 4 == 0) && (year % 100 != 0));
    pritnf("%d\n", k);
}

Output

The positions (offsets) where the two files differ.

Ex. 0
23
91
156
157
leap-year-mod.c 15

Sample Input  Download

Sample Output  Download




Discuss




14835 - Friendship   

Description

Write a program to determine friendship relationships.
First, we need to define what a person is. We assume there are n people, each with an integer id between 1 and n, and a name of at most 32 characters. According to the usual definition, friendship is mutual.

Suppose you have a binary file friends that contains all friendship information.
The file friends contains the following data in order:

  • The number of people n, occupying 4 bytes.

  • The contents of n structs of type person.

  • The number of friendship pairs f, occupying 4 bytes.

  • The contents of f structs of type friends.

Next, you need to read a series of commands from the keyboard.
Each command contains two names.
If the two names are friends—that is, if there exists a struct friends entry that matches the two names—output "yes"; otherwise, output "no".

The program must process all input until EOF.

Input

The two names.

Ex. John Mary
Tom Mary
Jack Tom

Output

Whether if they are friends.
Ex. yes
no
no

Sample Input  Download

Sample Output  Download




Discuss




14836 - Reverse output of linked sequence data   

Description

Implement the function print_list_backward to print the data in a linked list in reverse order.
First, the header file for the linked list is defined below.

linked-list.h

struct listnode {
    int data;
    struct listnode *next;
};
typedef struct listnode ListNode;

The main program and sample input/output are shown below.
Please implement the function print_list_backward.
Note that although the numbers are input from small to large, the method used in the main program inserts new numbers at the front of the list.
Therefore, the final list is stored in reverse order, so the result of reverse printing should appear from small to large.

print-list-backward-main.c

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "linked-list.h"
void print_list_backward(ListNode *ptr);
int main(void)
{
    int n;
    ListNode *head;
    ListNode *previous = NULL;
    while (scanf("%d", &n) != EOF) {
        head = (ListNode*)malloc(sizeof(ListNode));
        assert(head != NULL);
        head->data = n;
        head->next = previous;
        previous = head;
    }
    print_list_backward(head);
    return 0;
}

 

Input

Several integers, one per line. Ends at EOF.

The main program inserts each integer at the head → list is reversed.

You should print the linked list backward, so output is from smallest to largest.

Ex. 1
2
3
4
5
6
7

Output

Each number printed on its own line.

Ex. 1
2
3
4
5
6
7
 

Sample Input  Download

Sample Output  Download




Discuss