Contest 2:Temperature Conversion

来源:互联网 发布:汽车导航软件安装 编辑:程序博客网 时间:2024/06/15 01:38

Description

Fahrenheit(F) and Centigrade(C) are used as unit of measuring the temperature. The conversion between them is: F = 32 + C*1.8; C = (F - 32)/1.8
We need you write a C program to convert temperature value under different unit.

Input

The input consists of n+1 lines.
There is one integer n which is the number of test cases in the first line.
From  2nd to last line, there are a char and a float number in each line, which represent the type and temperature value. Two elements are seperated by a space. A 'C' represent the Centigrade temperature  and an 'F' for Fahrenheit temperature. You need convert Centigrade temperature to Fahrenheit temperature, vice versa.

Output

The ounput consists of n lines. Each contains a float value which is converted result. No return charactor for the last line.
The float value should retain 2 digits after the decimal point.

here is a sample,

input:
2
C 10.30
F 90.41

output:
50.54
32.45

Because
C->F: 32+10.3*1.8 = 50.54
F->C: (90.41-32)/1.8 = 32.45

Sample Input

2C 10.30F 90.41

Sample Output

50.5432.45

HINT

#include <stdio.h>#include <stdlib.h>int main()  { char ch;    int n,i;    scanf("%d\n",&n);    float a[n];    for(i=1;i<=n;i++){    scanf("\n%c%f",&ch,&a[i]);    int b=ch;    if(b==67)    a[i]=32+a[i]*1.8;    else if(b==70)    a[i]= (a[i]-32)/1.8;}    for(i=1;i<=n;i++){    printf("%.2f\n",a[i]);}    return 0;}

原创粉丝点击