SZU:G32 Mass fraction

Judge Info

  • Memory Limit: 32768KB
  • Case Time Limit: 5000MS
  • Time Limit: 5000MS
  • Judger: Float Numbers (1e-4) Judger

Description

The chemists are well known because of their weird. Especially when they add water or salt in the same beaker over and over again. Moreover, the still hope you can tell him the mass fraction of the liquor after many operations. In case of your forgetting your junior school chemistry class, now we particularly give you the formula of the mass fraction.

w=a/(a+b)×100% here w means the mass fraction, a means the mass of the salt, and b means the mass of water.

Input

The first line contains two integers, representing the mass of water and salt initially. Than each line will represent a operation. The operation contains:

  • 1. To add some salt into the beaker, the code is "salt x". x is a float number meaning the measure of salt The chemists add
  • 2. To add some water into the beaker, the code is "water x". x is a float number meaning the measure of water The chemists add
  • 3. Showing the mass fraction currently and the code is "show".
  • 4. Exit the test. The code is "exit".

The number will not be larger than 1e9.

Output

Output should be according to the operation. Print the mass fraction of the liquor. All the answer has an absolute error within 1e-4, will be consider as correct answer.

Sample Input

1.5 0.5
salt 0.5
water 1.5
show
exit

Sample Output

0.25

解题思路:printf("%g\n", a/sum);  %g 指省略后面所有无效的0。 虽然这题很简单,但是每一道水题都要认真对待并且总结。

 1 #include <stdio.h>
 2 #include <string.h>
 3 
 4 char A[10];
 5 
 6 int main()
 7 {
 8     float a,b,sum,c,d;
 9     scanf("%f%f",&b,&a);
10     while(1){
11         memset(A,'\0',sizeof(A));
12         scanf("%s", A);
13         if(strcmp(A,"salt")==0){
14             scanf("%f",&c);
15             a+=c;
16             continue;
17         }
18         if(strcmp(A,"water")==0){
19             scanf("%f",&d);
20             b+=d;
21             continue;
22         }
23         if(strcmp(A,"show")==0){
24             sum=a+b;
25             printf("%g\n", a/sum);
26             continue;
27         }
28         if(strcmp(A,"exit")==0){
29             break;
30         }
31 
32     }
33     return 0;
34 }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值