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。 虽然这题很简单,但是每一道水题都要认真对待并且总结。
#include <stdio.h>
#include <string.h> char A[]; int main()
{
float a,b,sum,c,d;
scanf("%f%f",&b,&a);
while(){
memset(A,'\0',sizeof(A));
scanf("%s", A);
if(strcmp(A,"salt")==){
scanf("%f",&c);
a+=c;
continue;
}
if(strcmp(A,"water")==){
scanf("%f",&d);
b+=d;
continue;
}
if(strcmp(A,"show")==){
sum=a+b;
printf("%g\n", a/sum);
continue;
}
if(strcmp(A,"exit")==){
break;
} }
return ;
}
SZU:G32 Mass fraction的更多相关文章
- R语言学习
1.清屏 Ctrl + L 2.退出 q() 3.设置工作空间 getwd() setwd('D:\\Program Files\\RStudio\\workspace') 4.显档当前工作目录下的文 ...
- jet flow in a combustion chamber
Table of Contents 1. contacts 2. Paper digest 2.1. LES vs. RANS 2.2. Dynamics of Transient Fuel Inje ...
- FLUENT质量加权平均和面积加权平均的区别【转载】
转载自:http://blog.sina.com.cn/s/blog_7ef78d170101bhfn.html 网上关于fluent中质量加强平均(Mass-Weighted Average)和面积 ...
- Usage of hdf2v3 and hdf2file
备注 修改Filetype,再执行hdf2file或hdf2tab,可以输出不同类型的数据.把Filetype设置成8,就是 Tecplot 格式的数据. <!DOCTYPE html PUBL ...
- Journal of Proteome Research | Prediction of an Upper Limit for the Fraction of Interprotein Cross-Links in Large-Scale In Vivo Cross-Linking Studies (分享人:张宇星)
题目:Prediction of an Upper Limit for the Fraction of Interprotein Cross-Links in Large-Scale In Vivo ...
- 新手!mass 设置问题
mass就是你那个物体的质量啊质量越大,惯性也越大重力也越大.假如你的刚体的mass为1,那么你只要给这个物体9.81N向上的力,你就可以抵消重力,让这个物体悬浮着:但假如这个物体的mass为10,你 ...
- [LeetCode] Fraction to Recurring Decimal 分数转循环小数
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
- How to: Change Sales Rep/Team via Mass Update
/* from: https://netsuite.custhelp.com/app/answers/detail/a_id/30057/kw/reassign%20sales */ How to c ...
- Fraction to Recurring Decimal
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
随机推荐
- hdu Rescue (bfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1242 简单优先队列搜索,自己好久不敲,,,,,手残啊,,,,orz 代码: #include < ...
- ZOJ 1649:Rescue(BFS)
Rescue Time Limit: 2 Seconds Memory Limit: 65536 KB Angel was caught by the MOLIGPY! He was put ...
- RQNOJ PID4 / 数列(位运算)
题目描述 给定一个正整数k(3≤k≤15),把所有k的方幂及所有有限个互不相等的k的方幂之和构成一个递增的序列,例如,当k=3时,这个序列是: 1,3,4,9,10,12,13,… (该序列实际上就是 ...
- Cocos2d-x 3.0final 终结者系列教程14-L新abel-Cocos2d-x公文
目 录 新文本标签类Label 其它文本标签 字体制作工具使用介绍 小结 https://github.com/chukong/cocos-docs/blob/master/manual/framew ...
- NYoj The partial sum problem(简单深搜+优化)
题目链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=927 代码: #include <stdio.h> #include & ...
- .NET中lock的使用方法及注意事项
lock就是把一段代码定义为临界区,所谓临界区就是同一时刻只能有一个线程来操作临界区的代码,当一个线程位于代码的临界区时,另一个线程不能进入临界区,如果试图进入临界区,则只能一直等待(即被阻止),直到 ...
- C#操作Xml:使用XmlReader读Xml
XmlDocument和XElement在读取Xml时要将整个Xml文档放到内存中去操作,这样做操作简单,但是很费内存和IO(可能是磁盘IO或者网络IO):而在有些场景下我们必须考虑尽可能节省内存和I ...
- 【百度地图API】建立全国银行位置查询系统(四)——如何利用百度地图的数据生成自己的标注
原文:[百度地图API]建立全国银行位置查询系统(四)--如何利用百度地图的数据生成自己的标注 摘要: 上一章留个悬念,"如果自己没有地理坐标的数据库,应该怎样制作银行的分布地图呢?&quo ...
- Socket 学习(三).5 UDP 的弱点
前面 讲到了,udp 传输文本的例子,发现 udp 确实 比tcp 高效一些,现在我用来传输文件,问题果然来了,结果发现 他不能一次 传输大于 64K的东西! 那么 我自然想到了 切包,多次发送,再合 ...
- 深入理解C指针之六:指针和结构体
原文:深入理解C指针之六:指针和结构体 C的结构体可以用来表示数据结构的元素,比如链表的节点,指针是把这些元素连接到一起的纽带. 结构体增强了数组等集合的实用性,每个结构体可以包含多个字段.如果不用结 ...