fork download
  1. import sys
  2. import math
  3.  
  4. input = sys.stdin.readline
  5.  
  6. T = int(input())
  7.  
  8. for _ in range(T):
  9. a, b = map(int, input().split())
  10.  
  11. if a==1:
  12. x,y,z = map(float, input().split())
  13.  
  14. if b==2:
  15. # cartesian -> cylinder
  16. r = math.sqrt(x*x+y*y)
  17.  
  18. if r < 1e-6:
  19. t = 0
  20. else:
  21. t = math.acos(x/r)
  22.  
  23. print(r,t,z)
  24.  
  25. if b==3:
  26. # cartesian -> spherical
  27. r = math.sqrt(x*x+y*y+z*z)
  28.  
  29. if r < 1e-6:
  30. u = 0
  31. t = 0
  32. else:
  33. u = math.asin(abs(z)/r)
  34. t = math.acos(x/r)
  35. print(r,u,t)
  36.  
  37. if a==2:
  38. r,t,z = map(float, input().split())
  39.  
  40. if b==1:
  41. # cylinder -> cartesian
  42. x = r*math.cos(t)
  43. y = r*math.sin(t)
  44. print(x,y,z)
  45.  
  46. if b==3:
  47. # cylinder -> spherical
  48. r_ = math.sqrt(r*r+z*z)
  49. if r_ < 1e-6:
  50. u = 0
  51. else:
  52. u = math.acos(abs(z)/r_)
  53. print(r_, u, t)
  54.  
  55. if a==3:
  56. r,u,t = map(float, input().split())
  57.  
  58. if r < 1e-6:
  59. print(0,0,0)
  60. continue
  61.  
  62. if b==1:
  63. # spherical -> cartesian
  64. r_ = r*math.sin(u)
  65. x = r_*math.cos(t)
  66. y = r_*math.sin(t)
  67. z = r*math.cos(u)
  68. print(x, y, z)
  69.  
  70. if b==2:
  71. # spherical -> cylinder
  72. r_ = r*math.sin(u)
  73. z = r*math.cos(u)
  74. print(r_,t,z)
  75.  
Success #stdin #stdout 0.03s 9920KB
stdin
6
1 2
0.00000000 0.00000000 0.00000000
1 3
0.00000000 0.00000000 0.00000000
2 1
0.00000000 0.00000000 0.00000000
2 3
0.00000000 0.00000000 0.00000000
3 1
0.00000000 0.00000000 0.00000000
3 2
0.00000000 0.00000000 0.00000000
stdout
0.0 0 0.0
0.0 0 0
0.0 0.0 0.0
0.0 0 0.0
0 0 0
0 0 0