zoukankan      html  css  js  c++  java
  • Conversions

    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.
     
    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.

    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
     
     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 int main(){
     5     int T;
     6     double amount;
     7     char unit[3];
     8     double total;
     9     int time;
    10 
    11     time=1;
    12 
    13     scanf("%d",&T);
    14 
    15     while(T--){
    16         scanf("%lf%s",&amount,unit);
    17 
    18         printf("%d ",time);
    19         time++;
    20 
    21         if(strcmp(unit,"kg")==0){
    22             total=amount*2.2046;
    23 
    24             printf("%.4lf lb
    ",total);
    25 
    26         }
    27 
    28         else if(strcmp(unit,"lb")==0){
    29             total=amount*0.4536;
    30 
    31             printf("%.4lf kg
    ",total);
    32         }
    33 
    34         else if(strcmp(unit,"l")==0){
    35             total=amount*0.2642;
    36 
    37             printf("%.4lf g
    ",total);
    38         }
    39 
    40         else if(strcmp(unit,"g")==0){
    41             total=amount*3.7854;
    42 
    43             printf("%.4lf l
    ",total);
    44         }
    45     }
    46     
    47 
    48     return 0;
    49 }
  • 相关阅读:
    Git常用命令总结
    JavaScript单元测试框架JsUnit基本介绍和使用
    Android Home键监听
    ASP.NET Core on K8S深入学习(3-2)DaemonSet与Job
    你必须知道的Dockerfile
    你必须知道的Docker数据卷(Volume)
    《人人都是产品经理》读书笔记
    ASP.NET Core on K8S深入学习(3-1)Deployment
    ASP.NET Core on K8S深入学习(2)部署过程解析与Dashboard
    .NET Core on K8S学习与实践系列文章 (2020版)
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/4087029.html
Copyright © 2011-2022 走看看