integer out of int range, changed to character type judgment was over. algorithm Training the most frequently occurring integersTime limit: 1.0s memory limit: 512.0MB Problem description
Write a program that reads a set of integers that are arranged in order from small to large, and that the number of n is also entered by the user, up to a maximum of 20. The program then counts the array and prints the value of the array element that has the most occurrences. If there are two element values that occur the same number of times, i.e. tie, then only the smaller value is printed.
Input format: The first line is an integer n,n? £? 20; Next there are n rows, each line represents an integer, and is arranged in order from small to large.
Output format: The output is only one line, that is, the most frequently occurring element value.
Input and Output sample sample input 5
100
150
150
200
250 Sample output 150
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;intMain () {Chara[ -][ -]; intn,ans,max,i,sum; Max=0; scanf ("%d",&N); for(i=0; i<n;i++) scanf ("%s",&A[i]); Sum=1; for(i=0; i<n;i++) { if(strcmp (a[i],a[i+1])==0) {sum++; } Else { if(max<sum) {Max=sum; Ans=i; } Sum=1; }} printf ("%s\n", A[ans]); return 0;}
Algorithm training the most frequently occurring integers