Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1517267
  • 博文数量: 399
  • 博客积分: 8508
  • 博客等级: 中将
  • 技术积分: 5302
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-14 09:28
个人简介

能力强的人善于解决问题,有智慧的人善于绕过问题。 区别很微妙,小心谨慎做后者。

文章分类

全部博文(399)

文章存档

2018年(3)

2017年(1)

2016年(1)

2015年(69)

2013年(14)

2012年(17)

2011年(12)

2010年(189)

2009年(93)

分类: LINUX

2010-05-13 18:20:00

// 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;
}
 
阅读(1954) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~