How is Google Calculator implemented?
When you search in Google "100F to C" how does it know to convert from Fahrenheit to Celsius? Similarly, conversion from d开发者_开发百科ifferent currencies and simple calculation.
What is the data structure used, or is it simple pattern matching the strings?
It's not exactly simple pattern matching. Evaluating the mathematical expressions you can enter is not trivial. For example, here's an algorithm that evaluates a math expression. That's just the evaluation, there's probably a lot of code to detect if it's even valid.
For the currencies conversion and other units, that's simple pattern matching.
it's simple pattern matching
try
100 kmh in mph = no calculation
100 kph in mph = 62.1371192 mph
精彩评论