// phoneNumber.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int MAX = 100;
char c[10][5] = {
" ",
" ",
"ABC",
"DEF",
"GHI",
"JKL",
"MNO",
"PQRS",
"TUV",
"WXYZ",
};
//每个数个有多少个字母可供选择
int total[10];
int answer[MAX];
void dump(int phone[],int n)
{
cout<
for(int i=0;i //cout< cout<}
//填充answer
void output(int phone[],int index)
{
int stack[MAX],top=-1,n=index-1;
while(n>=0)
{
//dump(phone,index);
while(n>=0)
{
if(answer[n] {
stack[++top]=n; //入栈
n--;
}else if(total[phone[n]]-1==answer[n]){
n--;
}
}
dump(phone,index);
if(-1 {
n=stack[top--];
answer[n]++;
memset(answer,0,sizeof(n)*n); //前面全部清0
}
}
}
void output1(int * phone,int *answer,int index,int n)
{
if(index == n)
{
for(int i=0;i cout< cout< return;
}
for(answer[index]=0;answer[index] output1(phone,answer,index+1,n);
}
int _tmain(int argc, _TCHAR* argv[])
{
for(int i=0;i<10;i++)
total[i] = strlen(c[i]);
memset(answer,0,sizeof(answer));
char phone1[100];
int phone2[100];
int index=0;
string number,tmp;
getline(cin,number);
istringstream sin(number);
while(sin>>tmp)
for(int i=0;i
{
phone1[index]=tmp[i];
phone2[index]=tmp[i]-'0';
index++;
}
phone1[index]='\0';
cout<<"电话号码为"< cout<
output(phone2,index);
getchar();
return 0;
}
阅读(2008) | 评论(0) | 转发(0) |