Digit Sequence | ||||||||||
| ||||||||||
Description | ||||||||||
Dawn is playing a game with some children. He gives them several arithmetic expressions and then asks them whether these expressions' value can form a digit sequence. The value of an expression is just the result we calculate them. For example, the value of expression "3*(7-2)" is 15. It's confirmed that each expression contains only '+', '-', '*', '/', '(', ')' characters. And the numbers in it are in the range from 0 to 2^31-1 which means there are no negative numbers. It is also guaranteed that the value of each arithmetic expression a non-negative number. If the expression contains 'A/B' character, you can assume that 'A' can always be divided with no remainder by 'B'. But what is the digit sequence? A digit sequence is defined as such a number queue which a former number's last digit is same to the later number's first digit. For examlpe, giving four numbers 123, 675, 398, 86 , They can form a digit sequence 123-398-86-675. On the other hand, if gives numbers 11,33, we can't get it. So the problem dawn leaving for the children is if the value of each expression can make up a digit sequence. Be sure that children must use all of the expressons' value. Since this is a litle difficult for children, can you write a program to help them. And if you can help children solve this problem, Dawn will give each child an ice cream including you.
|
转载于:https://www.cnblogs.com/-sunshine/archive/2012/08/18/2645220.html