3248 - EE2310 Midterm Exam Scoreboard

Time

2025/10/20 10:00:00 2025/10/20 12:40:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

14708 - Longest double palindrome   

Description

(30 points)

A palindrome (回文) is a sequence of integers of length at least 1 that reads the same forwards and backwards.
For example:

  • (1, 3, 5, 3, 1), (1, 2, 2, 1), and (1) are all palindromes.

If we concatenate two palindromes, we obtain a double palindrome.
For example:

  • (1, 3, 5, 3, 1) + (1, 2, 2, 1) = (1, 3, 5, 3, 1, 1, 2, 2, 1)

  • (1, 3, 5, 3, 1) + (1)  = (1, 3, 5, 3, 1, 1)

are both double palindromes.

Now, given a sequence of integers of length n, please find the longest double palindrome contained in it.

If there are multiple with the same maximum length, output the one that appears last.

 

(Hint

  • You may need to use nested for-loops to check all possible subsequences of the sequence.

  • You may write a a loop to check whether a subsequence is a palindrome.

  • To form a double palindrome, split the subsequence into two parts and check if both parts are palindromes.

  • Keep track of the longest length found, and if there are multiple with the same length, choose the one that appears last.

)

Input

  • The first line contains one integer n (2 ≤ n ≤ 100), the length of the sequence.

  • The second line contains n integers, representing the sequence.

Output

  • Print the longest double palindrome as a sequence of integers separated by spaces.
  • If multiple answers exist, print the one appearing last in the sequence.

Ensure that the output, including formatting 輸出格式, exactly matches the provided samples.

Sample Input  Download

Sample Output  Download




Discuss




14760 - Check if line passes through point (3,18)   

Description

(20 points)

You are given four positive integers a, b, c, d, which represent two distinct points (a, b) and (c, d).

Determine whether the line connecting (a, b) and (c, d) passes through the point (3, 18).

If it does, output 1; otherwise, output 0.

(Hint: Translate(平移) the coordinates so that (3, 18) becomes the origin, then check collinearity.

This can be implemented by verifying whether both points satisfy the same line equation of the form y = ax + b.)

Input

Input four integers: a, b, c, d.

Output

One integer:

1 if the line passes through (3,18), otherwise 0.

Ensure that the output, including formatting 輸出格式, exactly matches the provided samples.

Sample Input  Download

Sample Output  Download

Tags




Discuss




14761 - Minimum Value in a Pointer Array   

Description

(20 points)

A pointer array is simply an array whose elements are pointers.

For example, if we declare:

int *iptr[10];

then iptr is an array containing ten integer pointers. Each element of iptr points to an integer stored in another array.

Your task is to write a function min that returns the minimum integer among the elements pointed to by a pointer array.

The function definition is:

int min(int *iptr[N], int n);

Example Usage

The following program shows how the min function can be used in the main function:

#include <stdio.h>
#define N 10
int min(int *iptr[N], int n);

int main (void)
{
    int i;
    int array[N];
    int *iptr[N];

    for (i = 0; i < N; i++) {
        scanf("%d", &(array[i]));
        iptr[i] = &(array[i]);
    }

    printf("%d\n", min(iptr, N));
    return 0;
}

int min(int *iptr[N], int n)
{
    // Your Task
}

Please implement the function min and complete the program in example usage.

Input

  • he input consists of N integers (where N = 10 in this problem).

  • These integers are read from standard input, separated by spaces or newlines.

Output

The program outputs the minimum value among the integers pointed to by the pointer array.

Ensure that the output, including formatting 輸出格式, exactly matches the provided samples.

Sample Input  Download

Sample Output  Download

Tags




Discuss




14780 - Uniform Invoice Prize Calculation   

Description

(30 points)

A receipt number for the uniform invoice (統一發票) consists of 8 digits.
Each lottery period announces 3 special prize numbers and 3 first prize numbers.

Write a program to calculate the total amount of money you win based on your receipt numbers.

megapx

Prize Calculation Rules

  • If all 8 digits of your receipt number match any special prize number, you win 2,000,000 TWD.

  • If all 8 digits of your receipt number match any first prize number, you win 200,000 TWD.

  • If the last 7 digits of your receipt number match the last 7 digits of any first prize number, you win 40,000 TWD.

  • If the last 6 digits of your receipt number match the last 6 digits of any first prize number, you win 10,000 TWD.

  • If the last 5 digits of your receipt number match the last 5 digits of any first prize number, you win 4,000 TWD.

  • If the last 4 digits of your receipt number match the last 4 digits of any first prize number, you win 1,000 TWD.

  • If the last 3 digits of your receipt number match the last 3 digits of any first prize number, you win 200 TWD.

The program first reads three special prize numbers, followed by three first prize numbers.
After that, it reads multiple receipt numbers (each is 8 digits).
Your program must process all receipt numbers until end-of-file (EOF) and output the total prize amount.

while (scanf("%d", &input) != EOF) {...}

Input

  • The first 3 lines contain the special prize numbers.

  • The next 3 lines contain the first prize numbers.

  • The remaining lines contain receipt numbers collected by the user.

  • The input terminates at EOF.

Here is the explanation of sample input

Special Prize Numbers #1 55138690
Special Prize Numbers #2 14764045
Special Prize Numbers #3 41175733
First Prize Numbers #1 68787608
First Prize Numbers #2 77978931
First Prize Numbers #3 11071074
Your Receipt Numbers #1 12378931
Your Receipt Numbers #2 68787608

 

Number of your receipt is less than 500.

Output

Output a single integer representing the total prize amount won from all the receipts.

 

Here is the explanation of sample output

  • For Receipt #1, the last 5 digits match the last 5 digits of First Prize #2, so you win 4,000 TWD.

  • For Receipt #2, all 8 digits match First Prize #1, so you win 200,000 TWD.

Therefore, the total prize amount you win in this uniform invoice lottery is 204,000 TWD.

Ensure that the output, including formatting 輸出格式, exactly matches the provided samples.

Sample Input  Download

Sample Output  Download

Tags




Discuss




14781 - Counting Word Frequency   

Description

(30 points)

Write a program that counts how many times each English word appears in the input text.

A word is defined as a sequence of consecutive English letters (A–Z or a–z).
Letters are case-sensitive, meaning "This" and "this" are considered different words.

Your program must read all input until end-of-file (EOF) and count the frequency of every distinct word found.

The output should be sorted by Frequency in ascending order; however, if two or more words have the same frequency, they should be sorted by the order defibned by the strcmp function in the C standard library (in <string.h>).

 

About strcmp function.

The strcmp() function compares two strings (str1 and str2) according to their ASCII.
It checks each character of both strings from left to right until:

  • The characters differ, or

  • The null terminator ('\0') is reached

Return Value Meaning Example
< 0 str1 comes before str2 in ASCII  strcmp("apple", "banana") → negative value
 = 0 str1 and str2 are identical strcmp("cat", "cat") → 0
 > 0 str1 comes after str2 in ASCII  strcmp("dog", "cat") → positive value

 

Example: String Sorting Using strcmp()

#include <stdio.h>
#include <string.h>

#define N 80
#define M 100

int main(void) {
    char s[N][M];       // input string
    char *ptrs[N];      // pointer array pointing to input sting
    char *temp;         // temp string for sorting
    int count = 0;      // number of input string
    int i, j;           // loop lindices


    // Read input string and store in to array s
    while (scanf("%s", s[count]) != EOF && count < N) {
        ptrs[count] = s[count];         // point to the current input string
        count++;                        // accumulate the number of input string
    }


    //sort the input string in ASCII 
    // only sort the pointer array poining to the input string
    for (i = 0; i < count - 1; i++) {
        for (j = i; j < count; j++) {
            if (strcmp(ptrs[i], ptrs[j]) > 0) {
                temp = ptrs[i];
                ptrs[i] = ptrs[j];
                ptrs[j] = temp;
             }
         }
     }

    

    // print out the sorting result
    for (i = 0; i < count; i++) printf("%s\n", ptrs[i]);
    return 0;
}
Input of Example Code Output of Example Code
mountain
coffee
river
sunshine
Mirror
forest
planet
window
teacher
ocean
windows

Mirror
coffee
forest
mountain
ocean
planet
river
sunshine
teacher
window
windows

Hint

You may need to sort strings in this program. You can modify the example code directly to complete your solution.

Input

  • The input consists of one or more lines of English text.

  • Input continues until EOF is reached.

  • You may assume:

    • The length of each line n satisfies 0 < n ≤ 80

    • The total number of distinct words m satisfies 0 < m ≤ 100

The commas and periods have been removed from the test data, so you don’t need to consider them.

Output

  • Output all distinct words and their corresponding frequencies.

  • Sort the output by:

    1. Increasing order of frequency

    2. ASCII (A–Z, a-z) when frequencies are equal

Each line of the output should contain a word’s frequency, followed by a space, and then the word itself.

Ensure that the output, including formatting 輸出格式, exactly matches the provided samples.

Sample Input  Download

Sample Output  Download

Tags




Discuss