If the order is unimportant, the numbers are integers and the range is known, then you can calculate for O(size) simply by creating an array of counters.
ArrayResize(counter,100);
ArrayInitialize(counter,0);
for(int i=ArraySize(source)-1;i>=0;i--) {
counter[source[i]]++;
}
int pos=ArrayMaximum(counter);
PrintFormat("Чаще всего встречалось число %d, аж %d раз",pos,source[pos]);
Otherwise, really - sort and from there select the longest sequence of identical ones.
So "otherwise" is an array of numbers of any type. So it's a template function. Well and sort and search.
if(c>=cd) { // ищем первое большее ">" или максимально большее ">=" при одинаковом количестве cd=c; // количество совпадений res=Mas[i]; // число } c=0; } return( res /*cd*/); // число|количество }
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Nope :)))
1,1,1,2,3,3,2,1,4,4,5
is the number of numbers of the same colour.
Alexey Kozitsyn meant: in a sorted array.Maximum number of identical values in a sequence?
1,1,1,2,3,3,2,1,4,4,5
Sorting:
1,1,1,1, 1,2, 2, 3,3,4,4,5
The output is 4 matching values of numbers (the number 5 in a single copy is not a matching value)
Array:
1,1,1,2,3,3,2,1,4,4,5
Sort by:
1,1,1, 1,2, 2, 3,3,4,4,5
The output is 4 matching values of numbers (the number 5 in a single copy is not a matching value)
Then it would sound something like: determine the number of numbers in a sequence that have duplicates.
Neither.
There are four known unknown numbers. You need to find the number of repeated numbers as in the example in my first post.
If the order is unimportant, the numbers are integers and the range is known, then you can count for O(size) simply by creating an array of counters.
ArrayResize(counter,100);
ArrayInitialize(counter,0);
for(int i=ArraySize(source)-1;i>=0;i--) {
counter[source[i]]++;
}
int pos=ArrayMaximum(counter);
PrintFormat("Чаще всего встречалось число %d, аж %d раз",pos,source[pos]);
If the order is unimportant, the numbers are integers and the range is known, then you can calculate for O(size) simply by creating an array of counters.
ArrayResize(counter,100);
ArrayInitialize(counter,0);
for(int i=ArraySize(source)-1;i>=0;i--) {
counter[source[i]]++;
}
int pos=ArrayMaximum(counter);
PrintFormat("Чаще всего встречалось число %d, аж %d раз",pos,source[pos]);
Maybe. It's not about the wording at the moment, it's about the solution. I'm sitting here solving...
That's odd.
Your option always gives out 1. It takes longer to figure out than it does to come up with your own. That's all the weirdness ;)
int Strange( const T &InArray[] )
{
int Res = 1;
T Array[];
const int Size = ArraySize(InArray);
if ((ArrayCopy(Array, InArray) == Size) && ArraySort(Array))
{
int Tmp = 1;
ArrayPrint(Array);
for (int i = 1; i < Size; i++)
{
if (Array[i - 1] != Array[i])
{
if (Tmp > Res)
Res = Tmp;
Tmp = 0;
}
Tmp++;
}
}
return(Res);
}
void OnStart()
{
int Array[] = {1, 2, 3, 1, 2, 1, 2, 2};
Print(Strange(Array));
}
This one seems to be too:
{
int Arr[]={1, 2, 4, 4, 2, 1, 2, 2, 1, 4, 1, 4, 3, 3, 3, 4, 3, 3, 1, 3, 4, 3, 3};
Comment( GetM(Arr) );
}
int GetM(int &Mas[])
{
int c=0,cd=0,res=-1;
ArraySort(Mas);
int ArrSize= ArraySize(Mas);
for(int i=0; i<ArrSize; i++) {
for(int x=i; x<ArrSize; x++) {
if(Mas[i]==Mas[ArrayMinimum(Mas,WHOLE_ARRAY,x)]) c++;
}
if(c>=cd) { // ищем первое большее ">" или максимально большее ">=" при одинаковом количестве
cd=c; // количество совпадений
res=Mas[i]; // число
}
c=0;
}
return( res /*cd*/); // число|количество
}