#include <iostream>
using namespace std;
void func(int* number, int n)
{
int i = 0;
char c[10][10] = {
"*",
"#",
"ABC",
"DEF",
"GHI",
"JKL",
"MNO",
"PQRS",
"TUV",
"WXYZ",
};
int total[10] = {1,1,3,3,3,3,3,4,3,4};
int* answer = NULL;
answer = new int[n];
memset(answer, 0 , n*sizeof(int));
while (1)
{
cout << "[";
for (i = 0; i < n; i++)
{
cout << answer[i];
}
cout << "]" << endl;
for (i = 0; i < n; i++)
{
cout << c[number[i]][answer[i]];
}
cout << endl << endl;
int k = n-1;
while(k >= 0)
{
if (answer[k] < total[number[k]] - 1)
{
answer[k]++;
break;
}
else
{
answer[k] = 0;
k--;
}
}
if (k < 0)
break;
}
delete[] answer;
}
void main()
{
//int test[] = {1,2,3};
//int test[] = {5,6,7,8};
int test[] = {2,3,4};
int len = sizeof(test)/sizeof(test[0]);
func(test, len);
cin >> len;
}
編程之美 - 電話號碼對應英語單詞
問題描述:
電話的號碼盤上一個數字對應着幾個字母,一串數字對應着幾種字母的組合。
現在給定一組數字,列出對應的字母的組合。
思路:
例如:4對應鍵盤上 GHI, 2對應鍵盤上 ABC
數字 42 的組合對應的字符串,用樹的表現形式:
42
4: G H I
2: A B A B A B
結果:GA, GB, HA, HB, IA, IB
代碼:
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.