Gelişmiş bir hesap makinesine girilecek bir dizeyi değerlendiren bir program yazmalısınız.
Program, stdin kullanarak girdiyi kabul etmeli ve doğru cevabı vermelidir. Hiçbir fonksiyonları Stdin kabul etmek gerekiyor diller için, işlevlerini üstlenecek edebilir readLine
ve print
bu görevleri işlemek için.
Gereksinimler:
- Herhangi bir "eval" işlevini kullanmaz
- Kayan nokta ve negatif sayıları idare edebilir
- En azından +, -, *, /, ve ^ operatörlerini destekler
- Normal düzeni geçersiz kılmak için parantez ve parantezleri destekler
- Operatörler ve sayılar arasında bir veya daha fazla boşluk içeren girişi idare edebilir
- Standart işlem sırasını kullanarak girişi değerlendirir
Test Kılıfları
Giriş
10 - 3 + 2
Çıktı
9
Giriş
8 + 6 / 3 - 7 + -5 / 2.5
Çıktı
1
Giriş
4 + [ ( -3 + 5 ) * 3.5 ] ^ 2 - 12
Çıktı
41
.0
sonunda bir iz olabilir . Hassasiyet konusunda pek emin değilim, ama daha fazlası daha iyi.
.0
sonunda tamsayılar varsa izleri varsa sorun olur mu? Ayrıca: hesap makinesinin ne kadar doğru olması gerekiyor (kayan nokta hassasiyetiyle ilgili)?