Array-10. Find the number of occurrences in an integer sequence (15)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.