Statistics

Problem Statement for "TemperatureScales"

Problem Statement

Due to historical reasons people measure temperature in different scales, such as Fahrenheit and Celsius. Your task is to convert a temperature from one scale to another. It is known that both scales are linear with respect to each other (i.e., there are real numbers a and b such that temperature t presented in the first scale can be converted to the second by the law t'=a*t+b).

You are given 5 ints: f1, the freezing point of water in the first scale; b1, the boiling point of water in the first scale; f2, the freezing point of water in the second scale; b2, the boiling point of water in the second scale; and t, the temperature in the first scale. Return t converted into the second scale.

Definition

Class:
TemperatureScales
Method:
convert
Parameters:
int, int, int, int, int
Returns:
double
Method signature:
double convert(int f1, int b1, int f2, int b2, int t)
(be sure your method is public)

Notes

  • The return value must be within 1e-9 absolute or relative error of the actual result.
  • Because the boiling and the freezing points of water depend on the atmospheric pressure, you may assume that both the scales are under the same circumstances.

Constraints

  • f1,b1,f2,b2 and t will each be between -1000 and 1000, inclusive.
  • f1 will be less than b1.
  • f2 will be less than b2.

Examples

  1. 0

    100

    0

    100

    28

    Returns: 28.0

    These are two identical scales, so temperatures in both of them coincide.

  2. 0

    100

    1

    101

    28

    Returns: 29.0

    The second scale is shifted up 1 degree relative to the first scale.

  3. -1000

    -999

    -1000

    1000

    1000

    Returns: 3999000.0

  4. -10

    0

    1

    2

    17

    Returns: 3.7

  5. 17

    98

    -123

    12

    22

    Returns: -114.66666666666667

  6. -507

    239

    -802

    -469

    -678

    Returns: -878.3310991957104

  7. 341

    537

    -27

    890

    -412

    Returns: -3549.964285714286

  8. -462

    977

    -546

    352

    426

    Returns: 8.151494093120222

  9. -540

    368

    -59

    313

    -742

    Returns: -141.75770925110132

  10. -534

    282

    -688

    948

    -203

    Returns: -24.377450980392158

  11. -933

    506

    378

    379

    -820

    Returns: 378.07852675469076

  12. -431

    -291

    4

    980

    442

    Returns: 6090.057142857143

  13. 213

    561

    -58

    36

    -115

    Returns: -146.5977011494253

  14. -523

    698

    515

    756

    -906

    Returns: 439.4037674037674

  15. -675

    474

    -395

    417

    -744

    Returns: -443.76240208877283

  16. -607

    416

    -556

    219

    88

    Returns: -29.484848484848484

  17. -934

    -411

    -462

    281

    788

    Returns: 1984.359464627151

  18. -94

    412

    -140

    886

    296

    Returns: 650.7905138339921

  19. -850

    -258

    7

    637

    -25

    Returns: 884.956081081081

  20. -853

    241

    671

    963

    -224

    Returns: 838.8866544789762

  21. 181

    970

    -395

    574

    680

    Returns: 217.8403041825095

  22. -27

    550

    -443

    -414

    -52

    Returns: -444.25649913344887

  23. -530

    -273

    -356

    841

    131

    Returns: 2722.6653696498056

  24. -903

    -138

    -887

    677

    -290

    Returns: 366.24444444444447

  25. -394

    -340

    599

    638

    -931

    Returns: 211.16666666666666

  26. 0

    324

    886

    959

    686

    Returns: 1040.5617283950617

  27. -395

    853

    -515

    774

    119

    Returns: 15.886217948717949

  28. -896

    -456

    -262

    877

    -677

    Returns: 304.91136363636366

  29. -218

    905

    -10

    380

    -719

    Returns: -183.9893143365984

  30. -783

    321

    -635

    866

    -644

    Returns: -446.0153985507246

  31. -10

    0

    1

    2

    17

    Returns: 3.7

  32. 17

    98

    -123

    12

    22

    Returns: -114.66666666666667

  33. 1

    2

    0

    1

    3

    Returns: 2.0

  34. 0

    100

    0

    100

    28

    Returns: 28.0

  35. -1000

    -999

    -1000

    1000

    1000

    Returns: 3999000.0

  36. -20

    20

    -7

    60

    0

    Returns: 26.5

  37. -1000

    1000

    10

    11

    20

    Returns: 10.51

  38. 50

    150

    750

    950

    23

    Returns: 696.0

  39. 3

    6

    4

    24

    2

    Returns: -2.6666666666666665

  40. 34

    98

    55

    56

    77

    Returns: 55.671875

  41. 5

    7

    5

    6

    1

    Returns: 3.0

  42. -1000

    -937

    -1000

    666

    347

    Returns: 34620.666666666664


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: