EricYang

Tech Spot of Eric

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 char c[10][10] =
 6 {
 7     "",       //0
 8     "",       //1
 9     "ABC",    //2
10     "DEF",    //3
11     "GHI",    //4
12     "JKL",    //5
13     "MNO",    //6
14     "PQRS",   //7
15     "TUV",    //8
16     "WXYZ",   //9
17 };
18 
19 int total[10] = {0,0,3,3,3,3,3,4,3,4};
20 const int TelLength = 2;
21 int number[TelLength] = {4,2};
22 int answer[TelLength]={0};
23 
24 //index表示号码的第几位
25 void search(int index)
26 {
27     if(index==TelLength)
28     {
29         for(int i=0; i<TelLength; i++)
30         {
31             cout<<c[number[i]][answer[i]];
32         }
33         cout<<endl;
34         return;
35     }
36     for(answer[index]=0; answer[index]<total[number[index]]; answer[index]++)
37     {
38         search(index+1);
39     }
40 }
41 int main()
42 {
43     search(0);
44     return 0;
45 }
posted on 2012-08-11 20:05  Eric-Yang  阅读(252)  评论(0编辑  收藏  举报