Page 1 of 1
10554  Calories from Fat
Posted: Sun Oct 08, 2006 1:19 pm
by dust_cover
Can someone tell me how to calculate the PERCENTAGE CALORIES to calories. I cant get it through!
Plz Help! Thanx in Advance
Posted: Mon Oct 09, 2006 11:52 pm
by sakhassan
 Post in an existing thread if possible;
 If there isn't one, create one with the problem number and title in the subject line;
 If you need to publish code, use code tags.
10554  Calories from Fat
Posted: Mon Jan 02, 2012 12:05 pm
by outsbook
For grams to Calories, you are given a rules that:
1g fat = 9 Calories,
1g protein = 4 Calories,
1g sugar = 4 Calories,
1g starch = 4 Calories,
1g alcohol = 7 Calories
I think now the problem is very easy.
Remember that use double for all calculation
Re: 10554  Calories from Fat
Posted: Thu Jul 24, 2014 1:04 pm
by uDebug
I think now the problem is very easy.
Honestly, I struggled with this problem. This is one of those questions that's verbose and so it's harder to distil out the essence.
That being said, here's some input / output I found useful during testing / debugging.
Input:
Code: Select all
3g 10g 10% 0g 0g
32% 300C 2% 0g 30g
4g 4% 900C 6% 5%
6g 5g 70g 100g 6g

13g 8% 10% 2g 3g
67% 30C 2% 5g 30g
54g 4% 8% 6g 5%
68g 5g 9g 1g 2g

32% 300C 2% 0g 30g
4g 4% 900C 6% 5%


AC Output:
Re: 10554  Calories from Fat
Posted: Thu Jul 24, 2014 1:06 pm
by uDebug
If you need help with this problem, check out this thread.
http://onlinejudge.uva.es/board/viewto ... 27&t=70265
Re: 10554  Calories from Fat
Posted: Thu Aug 01, 2019 11:14 am
by Dominik Michniewski
Could anyone post more test cases ?
I am almost sure that my algorithm is correct, but I am getting WA
Idea of algorithm is:
1. convert grams to calories;
2. convert percents to calories;
3. when the whole dataset is read, sum up every type of ingridients and count percentage for fat
I have tested my program against random input (5 000 products with 120 lines per product)  the results are the same as the one given from uDebug page ...
My code is below (I do not like to post code, but I am too frustrated with this problem):
Re: 10554  Calories from Fat
Posted: Fri Aug 02, 2019 2:26 pm
by Dominik Michniewski
I have found problem  it was related to rounding ...
Example case:
Result is exactly 22.5%  rounding to nearest integer can be painful