字母对应数字

  1. /*Description
  2. Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or phrase. For example, you can call the University of Waterloo by dialing the memorable TUT-GLOP. Sometimes only part of the number is used to spell a word. When you get back to your hotel tonight you can order a pizza from Gino‘s by dialing 310-GINO. Another way to make a telephone number memorable is to group the digits in a memorable way. You could order your pizza from Pizza Hut by calling their ``three tens‘‘ number 3-10-10-10.
  3. The standard form of a telephone number is seven decimal digits with a hyphen between the third and fourth digits (e.g. 888-1200). The keypad of a phone supplies the mapping of letters to numbers, as follows:
  4. A, B, and C map to 2
  5. D, E, and F map to 3
  6. G, H, and I map to 4
  7. J, K, and L map to 5
  8. M, N, and O map to 6
  9. P, R, and S map to 7
  10. T, U, and V map to 8
  11. W, X, and Y map to 9
  12. There is no mapping for Q or Z. Hyphens are not dialed, and can be added and removed as necessary. The standard form of TUT-GLOP is 888-4567, the standard form of 310-GINO is 310-4466, and the standard form of 3-10-10-10 is 310-1010.
  13. Two telephone numbers are equivalent if they have the same standard form. (They dial the same number.)
  14. Your company is compiling a directory of telephone numbers from local businesses. As part of the quality control process you want to check that no two (or more) businesses in the directory have the same telephone number.
  15. Input
  16. The input will consist of one case. The first line of the input specifies the number of telephone numbers in the directory (up to 100,000) as a positive integer alone on the line. The remaining lines list the telephone numbers in the directory, with each number alone on a line. Each telephone number consists of a string composed of decimal digits, uppercase letters (excluding Q and Z) and hyphens. Exactly seven of the characters in the string will be digits or letters.
  17. Output
  18. Generate a line of output for each telephone number that appears more than once in any form. The line should give the telephone number in standard form, followed by a space, followed by the number of times the telephone number appears in the directory. Arrange the output lines by telephone number in ascending lexicographical order. If there are no duplicates in the input print the line:
  19. No duplicates.
  20. */
  21. #include <iostream>
  22. #include <math.h>
  23. #include <string>
  24. #include <map>
  25. using namespace std;
  26. #include <fstream>
  27. //ifstream fin("C:\\Users\\yw\\Desktop\\E\\E.2.dat");
  28. //ofstream fout("result1.txt");
  29. //#define cout fout
  30. //#define cin fin
  31. int main()
  32. {
  33. int n;
  34. cin>>n;
  35. //getchar();
  36. map<string,int>result; //存结果对应的map的
  37. map< string,int>::iterator iter; //建立反向迭代器
  38. map<char,int>num;
  39. // char num[91];
  40. num[‘A‘ ]=num[‘B‘]=num[‘C‘]=‘2‘; //字母对应的数字
  41. num[‘D‘ ]=num[‘E‘]=num[‘F‘]=‘3‘;
  42. num[‘G‘ ]=num[‘H‘]=num[‘I‘]=‘4‘;
  43. num[‘J‘ ]=num[‘K‘]=num[‘L‘]=‘5‘;
  44. num[‘M‘ ]=num[‘N‘]=num[‘O‘]=‘6‘;
  45. num[‘P‘ ]=num[‘R‘]=num[‘S‘]=‘7‘;
  46. num[‘T‘ ]=num[‘U‘]=num[‘V‘]=‘8‘;
  47. num[‘W‘ ]=num[‘X‘]=num[‘Y‘]=‘9‘;
  48. while(n--)
  49. {
  50. char word[100]; //注意字符可能很多
  51. cin>>word;
  52. char *p=word;
  53. string temp="";
  54. int count=0;
  55. while( (*p)!=‘\0‘) //转换数字
  56. {
  57. if( (*p>=‘A‘&&*p<‘Q‘)||(*p>‘Q‘&&*p<‘Z‘) )
  58. {
  59. temp+=num[*p];
  60. count++; p++;
  61. if(count==3)
  62. temp+=‘-‘;
  63. }
  64. else if( *p>=‘0‘&&*p<=‘9‘ )
  65. {
  66. temp+=(*p);
  67. count++; p++;
  68. if(count==3)
  69. temp+=‘-‘;
  70. }
  71. else p++;
  72. }
  73. iter=result.find(temp); //查找时候在map里面有
  74. if(iter==result.end() )
  75. result[temp]=1;
  76. else
  77. result[temp]=iter->second+1; //有就数字加一
  78. }
  79. int ok=1;
  80. for(iter = result.begin(); iter != result.end(); iter++) //利用方向迭代器输出数据
  81. {
  82. if(iter->second>1)
  83. {cout<<iter->first<<‘ ‘<<iter->second<<endl; ok=0;}
  84. }
  85. if(ok) cout<<"No duplicates."<<endl;
  86. return 0;
  87. }

来自为知笔记(Wiz)

附件列表

时间: 2024-08-05 23:47:40

字母对应数字的相关文章

WORD2010如何把全角字母和数字批量转换成半角

个人觉得全角字符看起来相当别扭,如果文档中存在大量全角形式的字母和数字,要如何把它们全部转化成半角的呢? 全角和半角 全角是指一个字符占用两个标准字符位置的状态.汉字字符和规定了全角的英文字符及国标GB2312-80中的图形符号和特殊字符都是全角字符. 半角的显示内码都是一个字节,英文字母.罗马数字.西方语言的符号都是半角形式. END 如何实现全角半角间的转换 全角字符占用更多字符,看起来也不够美观,如何将全角字符转换成半角的呢?这里我们可以利用word来实现.   不论是txt文档还是其他什

php正则匹配用户名必须包含字母和数字且大于6位

php正则匹配用户名必须包含字母和数字且大于6位 UEditor 1.4.3版本中去掉本地自动保存功能 右键菜单没有新建文本文档txt 常见HTTP错误代码大全 http常见状态码 eclipse内存溢出错误 为什么井盖是圆的?--揭开面试题的神秘面目! Linux Centos 6.6搭建SFTP服务器 密码强度检测 JS判断检测用户输入密码强度代码 对程序员来说,提高薪水最好的建议是什么? CSS3仿淘宝右侧固定导航悬浮层 jQuery仿淘宝网登录拖动滑块验证码代码 jQuery单击div更

汇编语言——统计一个字符串中的大写字母、小写字母、数字和其他字符的个数,并显示

;统计字符串中大写字母.小写字母.数字.其他字符的个数DATAS SEGMENT buf db '12ADdf#gh592HKL*','$' tp1 db 0;大写字母个数 tp2 db 0;小写字母个数 tp3 db 0;数字的个数 tp4 db 0;其他字符的个数 str1 db 'the number of big is:','$' str2 db 'the number of small is:','$' str3 db 'the number of number is:','$' st

【转】正则表达式 匹配中文,英文字母和数字及_的写法!同时控制长度

匹配中文:[\u4e00-\u9fa5] 英文字母:[a-zA-Z] 数字:[0-9] 匹配中文,英文字母和数字及_: ^[\u4e00-\u9fa5_a-zA-Z0-9]+$ 同时判断输入长度:[\u4e00-\u9fa5_a-zA-Z0-9_]{4,10} ^[\w\u4E00-\u9FA5\uF900-\uFA2D]*$ 1.一个正则表达式,只含有汉字.数字.字母.下划线不能以下划线开头和结尾:^(?!_)(?!.*?_$)[a-zA-Z0-9_\u4e00-\u9fa5]+$  其中:^

常用的正则表达式-匹配中英文、字母和数字

在做项目的过程中,使用正则表达式来匹配一段文本中的特定种类字符,是比较常用的一种方式,下面是对常用的正则匹配做了一个归纳整理. 匹配中文:[\u4e00-\u9fa5] 英文字母:[a-zA-Z] 数字:[0-9] 匹配中文,英文字母和数字及_: ^[\u4e00-\u9fa5_a-zA-Z0-9]+$ 同时判断输入长度: [\u4e00-\u9fa5_a-zA-Z0-9_]{4,10} ^[\w\u4E00-\u9FA5\uF900-\uFA2D]*$ 1.一个正则表达式,只含有汉字.数字.字

工具类:获得随机字母和数字的组合(字母+数字组合,字母组合,数字组合)

package util; import java.util.Random; /** * * @author jkfeng * 获得随机字母和数字的组合(字母+数字组合,字母组合,数字组合) * */ public class RandomCharOrNumUtil { public static void main(String[] args) { System.out.println(getCharAndNum(6)); System.out.println(getChar(6)); Sys

(转)求正则表达式,密码必须包含大写字母、小写字母、数字

1.必须只能是 大写字母.小写字母和数字构成的密码2.大写字母.小写字母.数字都至少出现一次 import java.util.regex.Pattern; import java.util.regex.Matcher; public class RegexRegexTest2 { public static boolean checkPassword(String password){ if(password.matches("\\w+")){ Pattern p1= Pattern

生成随机字母字符串(数字字母混和)

1.生成随机字母字符串(数字字母混和) /// 生成随机字母字符串(数字字母混和) /// /// 待生成的位数 /// 生成的字母字符串 private string GenerateCheckCode(int codeCount) { int rep = 0; string str = string.Empty; long num2 = DateTime.Now.Ticks + rep; rep++; Random random = new Random(((int)(((ulong)num

php面试题:如何知道一个未知长度的字符串哪个字符出现的次数最多?(字符串可由字母,数字及其他字符组成)请写出代码。

如何知道一个未知长度的字符串哪个字符出现的次数最多?(字符串可由字母,数字及其他字符组成)请写出代码. $str="asdfgfdas323344##$\$fdsdfg*$**$*$**$$443563536254fas";//任意长度字符串 //解法一(最快速的解法,但是基本功要扎实) $arr=str_split($str); $arr=array_count_values($arr); arsort($arr); print_r($arr); //解法二(对逻辑能力有一定要求)

OJ刷题之《统计出其中英文字母、数字、空格和其他字符的个数》

题目描述 输入一行字符,分别统计出其中英文字母.数字.空格和其他字符的个数. 输入 一行字符 输出 统计值 样例输入 aklsjflj123 sadf918u324 asdf91u32oasdf/.';123 样例输出 23 16 2 4 代码如下: #include <iostream> #include <cstdio> using namespace std; int main() { char str[50]; int i=0,n1=0,n2=0,n3=0,n4=0; ge