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.
The first line contains two integers, representing the mass of water and salt initially. Than each line will represent a operation. The operation contains:
The number will not be larger than 1e9.
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.
1.5 0.5 salt 0.5 water 1.5 show exit
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 }