Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

look for the best arithmetic  RSS feed

 
Song Guo
Greenhorn
Posts: 24
Chrome Java Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are 5 events, they (24 hours) occurs in one day , the number of occurrences stored in the array timeCount [i] [j], where i = 0,1,2,3,4 ,says that five events; j = 0 , 1,2 ,...... 22,23, respectively 0:00 to 1:00, 1:00 to 2:00 ...... 23:00 to 0:00,says that the number of occurrences of each hour, output the bet time period which are the highest number of the 5 events , I think the key is to find out that some of the best time period to make the event most often occurs during this time period.

How to make it using java?
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem is asking the program to sum the number of events for each hour and return the hour with the largest sum of the 5 events. So in pseudo code, the program would look something like


The problem statement suggests that one hour will be a clear winner, but the above doesn't account for the possibility of there being more than one hour with the same number of max events.

 
Song Guo
Greenhorn
Posts: 24
Chrome Java Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For instance(event 1),0:00-1:00,the occurrence is 2,1:00-2:00 100,2:00-3:00 120.Output is 1:00-3:00,the occurrence is 220 istead of 0:00-3:00,the occurrence is 221(1 is very small compared to 100).How to find the time period like this ? Thanks!
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to find the maximum occurrence of a single event rather than the sum of the five events, you'll have to search each element of the array for the max value. When you find the max value, the i, j indexes of that value will provide your answer: the max event will be i + 1 and the hour that the max event occurred will be j to j + 1 (or j to 00, if j = 23).

I won't code it for you. Attempt to code it yourself. If you get stuck, come back with your code to show what you need help with.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!