2011-12-17 06:13:33
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1985
题意:单位换算。
mark:打表非常方便。
代码:
# include <stdio.h>
# include <string.h>
char tab[4][5] = {"kg", "lb", "l", "g"} ;
char outtab[4][5] = {"lb", "kg", "g", "l"} ;
double rate[4] = {2.2046, 0.4536, 0.2642, 3.7854} ;
char str[5] ;
int main ()
{
int T, i, nCase = 1 ;
double num ;
scanf ("%d%*c", &T) ;
while (T--)
{
scanf ("%lf %s%*c", &num, str) ;
for (i = 0 ; i < 4 ; i++)
if (strcmp(str, tab[i]) == 0) break ;
printf ("%d %.4lf %s\n", nCase++, num*rate[i], outtab[i]) ;
}
return 0 ;
}