DRINK  Drink, on Ice
A good drink is always served on ice. That said, the amount of ice is what makes the difference. If it is too much, the drink will be well cooled, however, this is a bit of fraud as there could be less ice (and more Vodka for example). On the other hand, if there is too little ice the drink is warm which is unacceptable. You are to help the bartender, of course neither with mixing nor drinking, but with calculating the expected outcome of such mixtures.
To make things easier, we assume that pure water is mixed with ice in a closed system, i.e., there is no problem with the outside temperature or the warming of the bottle, etc. Therefore, after a some time has passed, the system may be regarded as balanced (there is no further change in temperature and no more melting or freezing). Your job is to calculate the final temperature of this balanced system and the amount of ice and water in this equilibrium state.
As you know from physics, it takes 4.19 Joule to heat one gram of water one Kelvin, whereas it takes 2.09 Joule if it is ice.
We define the capacities c_{w} = 4.19 J/(g*K)
and c_{i} = 2.09 J/(g*K)
.
Melting one gram of ice takes 335 Joule, where the temperature remains constant at zero.
We define the constant e_{m} = 335 J/g
.
The total thermal energy of the ice and the water before the experiment is equal to the thermal energy of the final mixture.
The figure below shows the energy of one gram of ice, icewatermixture, or water, where the temperature is measured relative to 30 degrees Celsius. The jump at 0 degrees represents the melting of ice to water. The amount of energy gained is proportional to the amount of ice already melted.
Input Specification
The input contains several test cases.
Each test case consists of four real numbers m_{w}, m_{i}, t_{w}, t_{i}
.
The mass of water m_{w}
and the mass of ice m_{i}
are both nonnegative, given in grams, and m_{w} + m_{i} > 0
.
The water temperature t_{w}
and the ice temperature t_{i}
follow, both given in degrees Celsius, and you may assume that 30 < t_{i} <= 0 <= t_{w} < 100
.
The last test case is followed by four zeroes.
Output Specification
For each test case output the amount of ice and water in grams and the final temperature of the mixture in degrees Celsius. All numbers must be rounded to one digit. Adhere to the sample output for the exact format to use.
Sample Input
100 20 50 10 100 22 0 0 100 35 25 10.5 10 90 25 28 0 0 0 0 Sample Output
0.0 g of ice and 120.0 g of water at 27.5 C 22.0 g of ice and 100.0 g of water at 0.0 C 6.0 g of ice and 129.0 g of water at 0.0 C 100.0 g of ice and 0.0 g of water at 4.2 C 
hide comments
One_touch_finish:
20140927 00:07:00
due to precision issue (at least in c++) double sometimes gives values such as 0.0, be careful! check your code for the case


Vishal:
20140709 14:22:35
@Wanderley Guimarăes


sagar bhavsar:
20130117 21:06:36
getting WA even when all test cases correct...i am using long double and %Lf in printf in C....is it coorect? 

nani:
20120717 14:29:45
Last edit: 20120717 14:42:04 

Loving Primes Yummy :D :):
20120606 11:57:28
I hate thermodynamics!!! 

Ozo:
20110614 22:28:46
A easy problem ,use basic thermodynamics. Last edit: 20111207 13:17:46 
Added by:  Wanderley Guimarăes 
Date:  20070921 
Time limit:  1s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ERL JSRHINO 
Resource:  University of Ulm Local Contest 2003 