|
Do you expect other's to write the code for you? It ain't work so here.
But it is quite simple. Give it a try:
Iterate over the array items using another iteration for each item looking for equal numbers. With equal numbers get the distance and check if it is larger than the previously detected maximum distance.
|
|
|
|
|
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!
But without giving you any code, I'll tell you how I'd do it: I'd create a struct to hold each distinct value and a sorted list of indexes in the array. I'd then fill out a collection of such structs - one for each distinct value in the array - and traverse the collection when complete to find the largest difference in indexes.
If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.
As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
any one work on sentiment analysis through google cloud library???please help
|
|
|
|
|
Member 12875047 wrote: please help
With what?
We have no idea what you have tried, what happened when you did, or what help you want from us.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Sentiment analysis indicates that your post is not to be taken seriously due to its lack of capitals, improper punctuation, tone, etc.
|
|
|
|
|
Here[^] you go.
This space for rent
|
|
|
|
|
Member 12875047 wrote: please help
Help on what ?
You gave a question a problem ?
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Hi, I'm creating a custom VScrollBar and I have problem getting the exact Y position of the thumb like the Windows.Forms.VScrollBar, I have searched online and I found some examples of custom scrollbars like:
How to skin scrollbars for Panels, in C#[^]
Custom Drawn Scrollbar[^]
The problem with these examples are that they don't get the exact top position of the thumb comparing to the windows scrollbar. I am getting a Top position that while scrolling becomes less than the real position
Doesn't anyone know how to calculate this?
|
|
|
|
|
Member 10498254 wrote: Doesn't anyone know how to calculate this? How are you calculating it?
|
|
|
|
|
I'm calculating it like this
decimal ratio = (decimal)((ClientRectangle.Height) - 2 * topButton.Height - ThumbSize()) / (Maximum - Minimum);
int thumbTopPosition = (int)((Value - Minimum) * ratio) + topButton.Height;
|
|
|
|
|
And what is wrong with the result?
|
|
|
|
|
the problem is that the Y position I get is smaller than the position of the Windows Scrollbar.
I tested my custom scrollbar with the Windows scrollbar with the same Maximum, Minimum, LargeChange and SmallChange, and when I get a Y position of 45 the other has a Y position little bit bigger than 45. The difference between the Y positions gets bigger as a set the Maximum value bigger.
|
|
|
|
|
I can only assume that your calculation is missing or adding something that Windows includes/excludes.
|
|
|
|
|
I'm thinking exactly the same. I'm missing something that windows includes. I hope I can figure it out.
|
|
|
|
|
and what is in the ThumbSize method?
I would avoid the decimal type, what you need is either float or double, since ratio could be a very small number; decimal is fine for monetary amounts, not for arbitrary scaling. Have you ever looked at the actual values while debugging?
modified 31-Dec-16 8:05am.
|
|
|
|
|
|
Hi Richard, all is fine, except for the scrollbar never reaching the bottom...
|
|
|
|
|
|
this is what is inside thumbSize. it works pretty well.
int trackHeight = (Height - (2 * topButton.Height));
int thumbHeight = (LargeChange / Maximum) * trackHeight;
I changed the values from decimal to float I'm still getting the same result. the thumb never reaches the bottom. I think there must be something else to add to the thumb position than I'm not adding.
|
|
|
|
|
If you can't reach the scroll's bottom, it means ratio is too small. As your math seems OK, I can imagine only two reasons:
1. a rounding down error, probably caused by a bad choice of data type (such as decimal only offering two fractional digits);
2. ThumbSize() returing too large a value; so please check and/or provide the exact code for that method.
Suggestion: take one example, note all the numbers, compare what they are (from logging or interactive debug session) with what they should be (manual calculation), you then should be able to see the error right away!
PS: ClientHeight isn't always the right value, e.g. when a HScrollBar appears, it reduces the VScrollBar's height!
|
|
|
|
|
I just solved the problem. it was the data type getting a rounding down error. You were right. Thanks for your help 
|
|
|
|
|
You're welcome
|
|
|
|
|
Hello those who are reading, I am a beginner in programmer and currently frequent in C#. I am working on building a cross-platform mobile application and I am confused on what to do. I know what I want my application to do and I am done with making the sketches and connecting them. Now I do not know how to proceed. ANY HELP/ADVICE WILL BE VERY APPRECIATED. THANK YOU.
|
|
|
|
|
Member 12929001 wrote: I am working on building a cross-platform mobile application and I am confused on what to do. That comes as no surprise. You've taken on a task that's challenging even for an experienced programmer! I suggest you instead focus on learning the basics of programming, select a target platform like Windows command line or Windows Forms, and eventually learn how to program for a mobile platform like iOS or Android. One step at a time.
Good luck!
/ravi
|
|
|
|