SZU:G32 Mass fraction
2014-02-15 15:34
225 查看
Judge Info
Memory Limit: 32768KBCase 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 }
相关文章推荐
- SZU:G32 Mass fraction
- SZU:B54 Dual Palindromes
- SZU:B47 Big Integer I
- SZU:J38 Number Base Conversion
- SZU:D89 The Settlers of Catan
- SZU:B47 Big Integer I
- SZU:B36 Reading books
- Travel Problem[SZU_K28]
- SZU:D89 The Settlers of Catan
- SZU : A18 (Climb Well)
- Fengshui-[SZU_B40]
- SZU:B47 Big Integer II
- SZU:B85 Alec's Eggs
- SZU:B47 Big Integer II
- Shader Model 3.0:Using Vertex Textures SM3:使用顶点纹理 (NVIDIA spec, 6800支持使用D3DFMT_R32F and D3DFMT_A32B32G32R32F的纹理格式实现Vertex Texture。)
- SZU : A11 Sequence
- SZU:B36 Reading books
- SZU 2015 Winter Training Day#1
- SZU:L89 Frog Encoding
- SZU : A18 (Climb Well)