เขียนโปรแกรมที่ใช้ตัวเลขสองตัวเป็นอินพุต คนแรกคือจำนวนมิติ - 0 สำหรับจุด, 1 สำหรับเส้นตรง, 2 สำหรับวงกลม, 3 สำหรับทรงกลม ตัวเลขที่สองคือรัศมีของวัตถุหรือถ้าเป็น 1 มิติก็จะเป็นตัวเลข เอาท์พุท 0 สำหรับ 0 มิติ ผลลัพธ์คือความยาว / พื้นที่ / ปริมาตรของวัตถุ
หากเราเรียกหมายเลขแรกหมายเลขn
ที่สองr
และผลลัพธ์x
เราจะได้รับ:
สำหรับ n = 0, x = 1
สำหรับ n = 1, x = 2 × r
สำหรับ n = 2, x = r 2 ×π
สำหรับ n = 3 x = ( 4 / 3 ) × R 3 ×π
และอื่น ๆ ... หากคุณต้องการ
หมายเหตุ:
กรณีที่ตัวเลขหนึ่งหรือทั้งสองเป็นลบหรือเมื่อตัวเลขแรกไม่ครบต้องไม่ครอบคลุม
โปรแกรมจะต้องไม่อ่านจากไฟล์ใด ๆ และอินพุตเพียงอย่างเดียวคือตัวเลขทั้งสอง
ผลลัพธ์ควรใช้เฉพาะตัวเลข (เช่นไม่ใช่ "14 * pi") และควรมีความถูกต้องกับทศนิยมอย่างน้อยสองหลัก
สำหรับ n = 0 คุณสามารถส่งออก 0 ถ้ามันทำให้รหัสสั้นลง
ย้อยเป็นพิเศษสำหรับคำตอบที่ครอบคลุม "โฟโตสเฟียร์" ขนาด 4 นิ้วและมากกว่า!
มันเป็นรหัสกอล์ฟดังนั้นคำตอบที่สั้นที่สุดในหน่วยไบต์ชนะ!
ตัวอย่าง:
1 1 -> 2
2 3 -> 28,27
3 1 -> 4,19
3 4,5 -> 381,70
1 9.379 -> 18.758
0 48 -> 1
== r
คือทรงกลมชุดของจุดที่มีระยะทางจากจุดกำเนิด<= r
คือลูกบอล จากนั้นเหล่านี้คือ 0 ลูก = จุด, 1 ลูก = ส่วน, 2 ลูก = ดิสก์, 3 ลูก = ลูก, 4 ลูก, 5 ลูก, และอื่น ๆ (แสดงเป็น " n
-ball = ชื่อสามัญ")