Soundex(map映射)
2015-07-02 11:06
190 查看
Soundex
Description
Soundex coding groups together words that appear to sound alike based on their spelling. For example, "can" and "khawn", "con" and "gone" would be equivalent under Soundex coding.
Soundex coding involves translating each word into a series of digits in which each digit represents a letter:
The letters A, E, I, O, U, H, W, and Y are not represented in Soundex coding, and repeated letters with the same code digit are represented by a single instance of that digit. Words with the same Soundex coding are considered equivalent.
Input
Each line of input contains a single word, all upper case, less than 20 letters long.
Output
For each line of input, produce a line of output giving the Soundex code.
Sample Input
Sample Output
Source
Waterloo local 1999.09.25
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 9494 | Accepted: 4720 |
Soundex coding groups together words that appear to sound alike based on their spelling. For example, "can" and "khawn", "con" and "gone" would be equivalent under Soundex coding.
Soundex coding involves translating each word into a series of digits in which each digit represents a letter:
1 represents B, F, P, or V 2 represents C, G, J, K, Q, S, X, or Z 3 represents D or T 4 represents L 5 represents M or N 6 represents R
The letters A, E, I, O, U, H, W, and Y are not represented in Soundex coding, and repeated letters with the same code digit are represented by a single instance of that digit. Words with the same Soundex coding are considered equivalent.
Input
Each line of input contains a single word, all upper case, less than 20 letters long.
Output
For each line of input, produce a line of output giving the Soundex code.
Sample Input
KHAWN PFISTER BOBBY
Sample Output
25 1236 11
Source
Waterloo local 1999.09.25
#include<cstdio> #include<iostream> #include<cstring> #include<map> using namespace std; int main() { string s,s1; int i,flag; map<char,int>mp; mp['B']=mp['F']=mp['P']=mp['V']=1; mp['C']=mp['G']=mp['J']=mp['K']=mp['Q']=mp['S']=mp['X']=mp['Z']=2; mp['D']=mp['T']=3; mp['L']=4; mp['M']=mp['N']=5; mp['R']=6; mp['A']=mp['E']=mp['I']=mp['O']=mp['U']=mp['H']=mp['W']=mp['Y']=0; while(cin>>s) { flag=0; if(mp[s[0]]!=0) { cout<<mp[s[0]]; } for(i=1;i<s.length();i++) { flag=mp[s[i-1]]; if(mp[s[i]]!=flag&&mp[s[i]]!=0) { cout<<mp[s[i]]; } } cout<<endl; } }
相关文章推荐
- 访问网络图片
- 阿里游戏大数据sesson2_RF&GBRT(上)
- IOS Masonry的基本使用
- JSP
- Allegro安装错误之cdsCommon.dll解决方法
- 斯坦福《机器学习》Lesson1-3感想-------3、线性回归二
- CGContextRef使用简要教程
- Mac android studio 连接svn导入项目遇到的问题
- Solr4.10使用教程(一):solr整合tomcat方法一
- RevitAPI: 关闭当前文档Close Active Document
- 在C++ 中 如何调用 C# 写的DLL
- Android 基于google Zxing实现对手机中的二维码进行扫描
- 黑马程序员--java基础学习笔记3
- Datazen笔记索引
- 自动布局
- 扎克伯格谈”人际交往”趋势
- [Gevent]gevent 网络抓取问答
- Viewbox在UWP开发中的应用
- ArduinoYun教程之OpenWrt-Yun与CLI配置Arduino Yun
- Python回调函数用法实例详解