+ 6

Can anyone write a code for this in c++ or any other programming language?

Adam is very fond of reading books. He has given rating to each book according to his likes and dislikes. He reads books one after other and he becomes happy everytime when he finishes a book and starts a higher rating book. Given the No. Of books and rating for each book, find maximum number of times he will become happy.

26th Apr 2017, 7:54 PM
sadiya zainab
sadiya zainab - avatar
5 Answers
+ 6
Thank you:-)
26th Apr 2017, 8:07 PM
sadiya zainab
sadiya zainab - avatar
+ 6
can you explain by writing algorithm?
27th Apr 2017, 3:53 AM
sadiya zainab
sadiya zainab - avatar
+ 5
ill give you the general algorithm int timesHappy = 0; if (thisBookRating > previousBookRating) { timesHappy++; }
26th Apr 2017, 8:06 PM
Edward
+ 2
there is actually some slightly complicated sorting to do here - you need to order the books so as to maximize the number of times you go from a low book to a high one. say you have 10 books. 5 are rated 0, 5 are rated 5. if you order them sequentially (0000055555), he is happy once. if you alternate low and high, he is happy 5 times.
27th Apr 2017, 3:50 AM
Jonathon Walker
Jonathon Walker - avatar
+ 1
hi, I think It's theory of probability, where we have some array( size equal number of books) when every element has value 0 or 1 (dislike/ like). Then we have to mix (swap randomly address of every element ) and then we be able to sort this array increasing value of happy if condition meets the requirements of task .
15th May 2017, 1:41 PM
Renat Khasanov
Renat Khasanov - avatar