电话号码与英文单词对应

问题:
电话的号码盘一般可以用于输入字母。如用2可以输入A、B、C,用3可以输入D、E、F等。
如:对于号码5869872,可以依次输入其代表的所有字母组合。如:JTMWTPA、JTMWTPB…
1. 设计程序,尽可能快地从这些字母组合中找到一个有意义的单词来表述一个电话号码。如:可以用单词“computer”来描述号码26678837

方法一:用三个(3为号码的个数)for循环


#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    printf("Hello, World!\n");
    const int TelLength = 3;
    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 number[TelLength]={4, 5, 6};
    int answer[TelLength];
    for(answer[0]=0; answer[0]<total[number[0]]; answer[0]++)
        for(answer[1]=0; answer[1]<total[number[1]]; answer[1]++)
            for(answer[2]=0; answer[2]<total[number[2]]; answer[2]++)
            {
                for(int i=0; i<3; i++)
                {
                    printf("%c", c[number[i]][answer[i]]);
                }
                printf("\n");
            }
    return 0;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值