//============================================================================ // Name : 编程之美电话号码对应英语单词.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> using namespace std; int number[100]; char c[10][10]={ "", //0 "", //1 "ABC", //2 "DEF", //3 "GHI", //4 "JKL", //5 "MNO", //6 "PQRS", //7 "TUV", //8 "WXYZ", //9 }; int total[10]={0,0,3,3,3,3,3,4,3,4}; int answer[10]; void compute(int length) { int k; while(true) { k=length-1; for(int i=0;i<length;i++) cout<<c[number[i]][answer[i]]<<" "; cout<<endl; while(k>=0) { if(answer[k]<total[number[k]]-1) { answer[k]++; break; } else { answer[k]=0; k--; } } if(k<0) break; } } void recursion(int length,int index) { if(index==length) { for(int i=0;i<length;i++) { cout<<c[number[i]][answer[i]]<<" "; } cout<<endl; return ; } for(answer[index]=0;answer[index]<total[number[index]];answer[index]++) { recursion(length,index+1); } } int main() { int length=3; number[0]=2; number[1]=3; number[2]=4; compute(length); recursion(length,0); return 0; }