Conversions
2024-10-19 11:42:21
Problem Description
Conversion between the metric and English measurement systems is relatively simple. Often, it involves either multiplying or dividing by a constant. You must write a program that converts between the following units:
Input
The first line of input contains a single integer N, (1
≤ N ≤ 1000) which is the number of datasets that follow.
Each dataset
consists of a single line of input containing a floating point (double
precision) number, a space and the unit specification for the measurement to be
converted. The unit specification is one of kg, lb, l, or g referring to
kilograms, pounds, liters and gallons respectively.
≤ N ≤ 1000) which is the number of datasets that follow.
Each dataset
consists of a single line of input containing a floating point (double
precision) number, a space and the unit specification for the measurement to be
converted. The unit specification is one of kg, lb, l, or g referring to
kilograms, pounds, liters and gallons respectively.
Output
For each dataset, you should generate one line of
output with the following values: The dataset number as a decimal integer (start
counting at one), a space, and the appropriately converted value rounded to 4
decimal places, a space and the unit specification for the converted
value.
output with the following values: The dataset number as a decimal integer (start
counting at one), a space, and the appropriately converted value rounded to 4
decimal places, a space and the unit specification for the converted
value.
Sample Input
5
1 kg
2 l
7 lb
3.5 g
0 l
Sample Output
1 2.2046 lb
2 0.5284 g
3 3.1752 kg
4 13.2489 l
5 0.0000 g
#include <stdio.h>
#include <string.h> int main(){
int T;
double amount;
char unit[];
double total;
int time; time=; scanf("%d",&T); while(T--){
scanf("%lf%s",&amount,unit); printf("%d ",time);
time++; if(strcmp(unit,"kg")==){
total=amount*2.2046; printf("%.4lf lb\n",total); } else if(strcmp(unit,"lb")==){
total=amount*0.4536; printf("%.4lf kg\n",total);
} else if(strcmp(unit,"l")==){
total=amount*0.2642; printf("%.4lf g\n",total);
} else if(strcmp(unit,"g")==){
total=amount*3.7854; printf("%.4lf l\n",total);
}
} return ;
}
最新文章
- android 两种实现计时器时分秒的实现,把时间放在你的手中~
- BZOJ4567[Scoi2016]背单词
- Android代码规范----按钮单击事件的四种写法
- php面向对象之__toString()
- 使用dynamic来简化反射实现
- 在python中编写socket服务端模块(二):使用poll或epoll
- zzu--2014年11月16日月潭赛 B称号
- Angular5.0.0新特性
- Nginx安装与代理
- [洛谷P1438] 无聊的数列
- iframe和form表单实现ajax请求上传数据
- C#中如何把int转换成两个字符的string
- nginx反向代理服务器获取不到端口的问题的解决办法
- HibernateUtil工具类的使用
- 第五篇:jmeter图形监控扩展
- 2017-2018-2 20165318 实验四《Android程序设计》实验报告
- Spark记录-Scala数组
- apache2.2 虚拟主机配置(转)
- 案例:用Redis来存储关注关系
- linux Composer 安装