您的位置:首页 > 编程语言

编程之美第三章-3.2-电话号码以及对应的单词

2015-05-08 14:22 183 查看
#include<iostream>
#include<string>
using namespace std;
const int max_length=9;
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 count=0;
int main()
{
int number[max_length]={2,3,4};
int answer[max_length]={0};
int length=3;
while(true)
{
for(int i=0;i<length;++i)
cout<<c[number[i]][answer[i]]<<" ";
count++;
cout<<endl;
int k=length-1;
while(k>=0)
{
if(answer[k]<total[number[k]]-1)
{
answer[k]++;
break;
}
else
{
answer[k]=0;
k--;
}
}
if(k<0)
break;
}
cout<<count<<endl;
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: