คุณต้องเขียนโปรแกรมที่ประเมินสตริงที่จะถูกป้อนลงในเครื่องคิดเลขขั้นสูง
โปรแกรมจะต้องยอมรับอินพุตโดยใช้ stdin และออกคำตอบที่ถูกต้อง สำหรับภาษาที่ไม่มีฟังก์ชั่นที่จะยอมรับ stdin คุณอาจถือว่าฟังก์ชั่นนั้นreadLine
และprint
จัดการงานเหล่านี้
ที่ต้องการ:
- ห้ามใช้ฟังก์ชั่น "eval" ใด ๆ
- สามารถจัดการกับจำนวนจุดลอยตัวและจำนวนลบ
- รองรับตัวดำเนินการอย่างน้อย +, -, *, / และ ^
- รองรับวงเล็บและวงเล็บสำหรับแทนที่คำสั่งปกติ
- สามารถจัดการกับการป้อนข้อมูลที่มีหนึ่งหรือมากกว่าช่องว่างระหว่างผู้ประกอบการและตัวเลข
- ประเมินอินพุตโดยใช้คำสั่งมาตรฐานของการดำเนินการ
กรณีทดสอบ
อินพุต
10 - 3 + 2
เอาท์พุต
9
อินพุต
8 + 6 / 3 - 7 + -5 / 2.5
เอาท์พุต
1
อินพุต
4 + [ ( -3 + 5 ) * 3.5 ] ^ 2 - 12
เอาท์พุต
41
.0
ที่ท้าย ฉันไม่แน่ใจเกี่ยวกับความแม่นยำ แต่ยังดีกว่า
.0
ที่ท้ายถ้าเป็นจำนวนเต็ม? นอกจากนี้: เครื่องคิดเลขต้องแม่นยำแค่ไหน (เกี่ยวกับความแม่นยำของจุดลอยตัวและเช่นนั้น)