将字母电话号码转换为数字 [英] Converting alphabetic phone number to numeric
本文介绍了将字母电话号码转换为数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将字母电话号码转换为数字电话号码?
翻译字母数字:
输入电话号码:1 -800-COL-LECT
1-800-265-5328
How do i convert an alphabetic phone number to a numeric phone number?
Translating alphabetic number:
Enter phone number:1-800-COL-LECT
1-800-265-5328
推荐答案
最简单的方法是创建一个数组并分配每个字母都是相应的数字。然后循环通过电话号码输入并用数字替换字母。
Simplest way is create an array and assign each letter it''s corresponding number. Then loop through the phone number input and replace the letter with number.
嗯......我想:
如果字符串s = 1800-COL-LECT
if(s [i] =='' - '')什么都不写
else ii(s [i]> == 0 || s [i] < == 9)写s [i]
if(s [i] ==''A''|| s [i] ==''B''|| s [i ] ==''C'')为DEF,GHI,JKL,MNO,PQRS,TUV和WXYZ写2
等。
Uhmm....I think:
if string s=1800-COL-LECT
If(s[i]==''-'') write nothing
else ii(s[i]>==0 || s[i]<==9)write s[i]
if(s[i]==''A''||s[i]==''B''||s[i]==''C'')write 2
etc for DEF,GJKL,MNO,PQRS,TUV and WXYZ.
我建议使用< ;文件ctype.h>分类函数isdigit()和isalpha()。你可能想把''a''和''''一样对待。而不是if语句中的逻辑表达式,我建议使用switch语句 - 它将更容易阅读:
I suggest using <ctype.h> classification functions isdigit() and isalpha(). You probably want to treat ''a'' the same as ''A''. Instead of the logical expression in the if statement, I suggest using a switch statement -- it will be easier to read:
展开 | 选择 | 换行 | 行号
这篇关于将字母电话号码转换为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文