Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2342315
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:01:32

#include

using namespace std;

int main ()
{
    char letter;
    int num[1000]={0};
    int  i=1;
    while(cin>>letter)
    {
     
         if(letter=='B'||letter=='F'||letter=='P'||letter=='V')
         {num[i]=1;
         if(num[i]!=num[i-1])
         cout<<1;
         i++;}
         else if(letter=='C'||letter=='G'||letter=='J'||letter=='K'||letter=='Q'||letter=='S'
         ||letter=='X'||letter=='Z')
         {num[i]=2;
         if(num[i]!=num[i-1])
         cout<<2;
         i++;}
         else if(letter=='D'||letter=='T')
         {num[i]=3;
         
         if(num[i]!=num[i-1])
         cout<<3;
         i++;}
         else if(letter=='L')
          {num[i]=4;
       
         if(num[i]!=num[i-1])
         cout<<4;
         i++;}
         else if(letter=='M'||letter=='N')
          {num[i]=5;
       
         if(num[i]!=num[i-1])
         cout<<5;
         i++;}
         else if(letter=='R')
         {num[i]=6;
       
         if(num[i]!=num[i-1])
         cout<<6;
         i++;}
         else
         i++;
    }
     
}
这个代码缺点是 上条命令跟下条效果连着 (如不明白 自己试试就知道了)
有什么解决办法~~

--------------------next---------------------
我把题目写出来吧 高人给看看

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.
Each line of input contains a single word, all upper case, less than 20 letters long. For each line of input, produce a line of output giving the Soundex code.
Sample Input
KHAWN
PFISTER
BOBBY
Output for Sample Input
25
1236
11


--------------------next---------------------

阅读(1144) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~