大學的新鮮人由於興趣不同,對於課程的選擇不盡相同,而校方希望他們所 選的課程盡量一致,所以設立了一個獎項,頒發給 選擇的「課程組合」為 「最受歡迎的課程組合」的學生。 • 一組課程受歡迎程度視所有剛好選擇該組課程的學生人數而定,如果沒有其 他「課程組合」的人數比此「課程組合」的人數高,則該課程為最受歡迎的 「課程組合」,請對每組測試資料輸出選擇最受歡迎的「課程組合」的人數。For the freshmen at the University, due to different interests, have varying choices in courses, and the university hopes to maximize the consistency of their course selections. Therefore, an award has been established, given to the student who chooses the 'course combination' that is the 'most popular course combination'. The popularity of a set of courses is determined by the number of students who choose exactly that combination of courses. If no other 'course combination' has more students than this 'course combination', then that course set is the most popular 'course combination'. Please output the number of students who have chosen the most popular 'course combination' for each set of test data.

Q2: 輸入輸出說明 • 輸入: • 有多組測試資料。每組測資第一列為整 數 n。代表n 個組合,後面有n列,每一 列為一個學生的選課組合,有五個3 位數 課程代號,中間以空格隔開(都是 100~499的整數) 。若 n 為 0 代表結束。 • 輸出: • 求最多人選擇的那組課程代號的人數, 若同時有超過一組最多人選擇的話則將 人數相加,例如 Sample 的第二組資料, 有三組不同的組合則答案為 1 + 1 + 1 = 3。

Input: There are multiple test cases. For each test case, the first line is an integer n, representing n combinations, followed by n lines, each line being a student's course selection combination with five 3-digit course codes, separated by spaces (all are integers from 100 to 499). If n is 0, it signifies the end of input. • Output: Find the number of students who have chosen the most popular set of course codes. If there are more than one such sets with the most selections, add their numbers together. For instance, in the second test case of the Sample, there are three different combinations, so the answer would be 1 + 1 + 1 = 3.

Description

Frosh commencing their studies at Waterloo have diverse interests, as evidenced by their desire to take various combinations of courses from among those available.University administrators are uncomfortable with this situation, and therefore wish to offer a conformity prize to frosh who choose the most popular combination of courses. How many frosh will win the prize?

Input

Untitled

Output

Untitled

Sample Input 1

3
100 101 102 103 488
100 200 300 101 102
103 102 101 488 100
3
200 202 204 206 208
123 234 345 456 321
100 200 300 400 444
0

Sample Output 1

2
3
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);

    while (n != 0) {
        int a[100][5];
        int frequency[100] = {0}; // Array to store the frequency of each combination
        int maxFrequency = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 5; j++) {
                scanf("%d", &a[i][j]);
            }
        }

        for (int i = 0; i < n; i++) {
            for (int g = i + 1; g < n; g++) {
                int matches = 0;

                for (int j = 0; j < 5; j++) {
                    for (int k = 0; k < 5; k++) {
                        if (a[i][j] == a[g][k]) {
                            matches++;
                            break; // Exit the inner loop if a match is found
                        }
                    }
                }

                // If all elements match, increment frequency
                if (matches == 5) {
                    frequency[i]++;
                    frequency[g]++;
                }
            }
        }

        // Find the maximum frequency
        for (int i = 0; i < n; i++) {
            if (frequency[i] > maxFrequency) {
                maxFrequency = frequency[i];
            }
        }

        int totalPopularCombinations = 0;

        // Count the number of combinations with the maximum frequency
        for (int i = 0; i < n; i++) {
            if (frequency[i] == maxFrequency) {
                totalPopularCombinations++;
            }
        }

        printf("%d\\n", totalPopularCombinations);

        // Read the next value of n
        scanf("%d", &n);
    }

    return 0;
}