UVa 10260 Soundex

 1  #include <stdio.h>
 2  #include <stdlib.h>
 3  #include <iostream>
 4  #include <algorithm>
 5  #include <string.h>
 6  #include <map>
 7  using namespace std;
 8  int main()
 9  {
10      string str;
11      map<char,char> m;
12      m['B']=m['F']=m['P']=m['V']='1';
13      m['C']=m['G']=m['J']=m['K']=m['Q']=m['S']=m['X']=m['Z']='2';
14      m['D']=m['T']='3';
15      m['L']='4';
16      m['M']=m['N']='5';
17      m['R']='6';
18      while(cin>>str)
19      {
20          int len=str.length();
21          string ans="";
22          for(int i=0;i<len;i++)
23          {
24              if(i==0 && m[str[i]]!=0) ans+=m[str[i]];
25              else
26              {
27                  if(m[str[i]]!=0 && m[str[i-1]]!=m[str[i]]) ans+=m[str[i]];
28              }
29          }
30          cout<<ans<<endl;
31      }
32      return 0;

33  }

留言

這個網誌中的熱門文章

Things a Little Bird Told Me: Confessions of the Creative Mind

UVa 12970 Alcoholic Pilots

UVa 483 Word Scramble