打印从数字创建的可能字符串
给定一个 10 位数字的电话号码,我们必须打印由此创建的所有可能的字符串。数字的映射与手机键盘上的数字映射完全相同。
即对于 1,0->没有信 对于2-> A,B,C
例如,1230 平均日增重 BDG CDG AEG...
c/c++ 中解决这个问题的最佳解决方案是什么?
Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone's keypad.
i.e. for 1,0-> No Letter
for 2-> A,B,C
So for example, 1230
ADG
BDG
CDG
AEG....
Whats the best solution in c/c++ to this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为递归解决方案适合这个问题。所以像这样:
I think a recursive solution would be good for this one. So something like:
无需递归。这是一个迭代方法的示例。它打印出所有可能性,但您可能不完全喜欢它的行为。问题留给读者自己去发现;-)
No need to go recursive. Here is an example of an iterative approach to start with. It prints out all the possibilities, but you may not entirely like its behaviour. The catch is left for the reader to discover ;-)
Smashery 的 python 解决方案的 C++ 版本:
A C++ version of Smashery's python solution: