/*************************************************************************
> File Name: TelephoneNumbers.cpp
> Author: Shaojie Kang
> Mail: kangshaojie@ict.ac.cn
> Created Time: 2015年09月11日 星期五 15时55分04秒
> Problem:
输出电话号码对应的英语单词
************************************************************************/
#include<iostream>
#include<vector>
using namespace std;
char dict[10][10] = {
"", "", "ABC", "DEF", "GHI", "JKL", "MNO", "PQRS", "TUV", "WXYZ"
};
int len[10] = {0, 0, 3, 3, 3, 3, 3, 4, 3, 4};
void GenerateWords(vector<int> &numbers, int index, vector<int> &answer)
{
int size = numbers.size();
if(index == size)
{
for(int i = 0; i < size; ++i)
cout<<dict[numbers[i]][answer[i]];
cout<<endl;
return;
}
for(answer[index] = 0; answer[index] < len[numbers[index]]; answer[index]++)
GenerateWords(numbers, index+1, answer);
}
int main()
{
int arr[] = {
2, 5, 3, 9, 6
};
vector<int> numbers(arr, arr + sizeof(arr)/sizeof(int));
vector<int> answer(numbers.size(), 0);
GenerateWords(numbers, 0, answer);
return 0;
}
「深度优先遍历」 输出电话号码对应的英语单词
最新推荐文章于 2024-07-26 01:45:52 发布