南邮 OJ 1442 temperature conversions

temperature conversions

时间限制(普通/Java) :  2000 MS/ 6000 MS          运行内存限制 : 65536 KByte
总提交 : 63            测试通过 : 51 

比赛描述

John is now madding a calculator that can do Centigrade and Fahrenheit temperature conversions.

In the formulas below, / means to divide, * means to multiply, - means subtract, + means to add and = is equal. Tc = temperature in degrees Centigrade, Tf = temperature in degrees Fahrenheit

To convert a Fahrenheit temperature into Centigrade:

Tc = (5/9)*(Tf-32)

For example, to convert a Fahrenheit temperature of 98.6°F into degrees Centigrade, first subtract 32 from the Fahrenheit temperature to get 66.6. Then you multiply 66.6 by five-ninths to get 37°C.

To convert a Centigrade temperature into degrees Fahrenheit:

Tf = ((9/5)*Tc)+32

For example, to convert a Centigrade temperature of 100 into degrees Fahrenheit, first multiply the Centigrade temperature reading by nine-fifths to get 180. Then add 32 to 180 and get 212°F.




输入

Line 1 contains an integer T: the number of test cases.

Next T lines, each contains an integer followed by a character ‘C’or ‘F’.


输出

   For each test case, if ended by ‘C’ it means the number before is Centigrade, and then please convert it to Fahrenheit. Else if ended by ‘F’, convert it to Centigrade. The result should be truncated to integer (1.9 => 1, see it?) in one line. Life is easy, isn’t it?


样例输入

2
100C
200F

样例输出

212F
93C

题目来源

NUPT ACM 2010 Personal Ranking Contest





#include<stdio.h>
int main(){
	int t,n;
	char c;
	scanf("%d",&t);
	while(t--){
		scanf("%d%c",&n,&c);
		if('C'==c){
			printf("%dF\n",n*9/5+32);
		}else if('F'==c){
			printf("%dC\n",(n-32)*5/9);
		}
	}
}





你可能感兴趣的:(ACM,Temperature,南邮OJ,conversi)