The subject asks to count the number of integers that occur in an integer sequence and their occurrences.
Input format:
The input gives the integer number N (0<n<=1000) in the sequence and n integers in a row. The numbers are separated by a space.
Output format:
Outputs the most frequently occurring integers and their occurrences in a row, separated by a space between the numbers. The title guarantees that such numbers are unique.
Input Sample:
10 3 2-1 5 3 4 3 0 3 2
Sample output:
3 4
#include <stdio.h> #define N 1000int Comp (const void *p, const void *q) { return * (int *) P-* (int *) Q;} int main (void) { int a[n + 1]; int I, J, N, Count, MaxCount, value; scanf ("%d", &n); for (i = 0; i < n; ++i) scanf ("%d", &a[i]); Qsort (A, n, sizeof (int), comp); /* Ascending sort */ maxCount = 0; /* Maximum number of times */ value = 0; /* Current Value */ i = 0; while (I < n) { count = 1; /* Number of occurrences per element * /for (j = i + 1; j < n && a[i] = = A[j]; ++j) ++count; if (Count > MaxCount) { maxCount = count; Value = A[i]; } i = j; /* Do not repeat lookup * /} printf ("%d%d\n", value, MaxCount); return 0;}
Array-10. Find the number of occurrences in an integer sequence (15)