记一道面试题

Write a function that given a string of digits and a target value, prints where to put +'s and *'s between the digits so they combine exactly to the target value. Note there may be more than one answer, it doesn't matter which one you print.
Examples:
"1231231234",11353 -> "12*3+1+23*123*4"
"3456237490",1185 -> "3*4*56+2+3*7+490"

"3456237490",9191 -> "no solution"

方案一:(不是俺想出)可供参考(用了穷举法)

Code

posted @ 2009-04-28 13:38  yangbinhe  阅读(573)  评论(1编辑  收藏  举报