回 帖 发 新 帖 刷新版面

主题:这个有什么错误是想不出阿

Soundex 
Time Limit:1000MS  Memory Limit:65536K
Total Submit:2212 Accepted:1117 

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: 


      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

http://acm.pku.edu.cn/JudgeOnline/problem?id=2608
#include<stdio.h>
#include<string.h>
//#include<stdlib.h>
int main()
{
 char str[20];
 int a[20];
 int i;

 while(scanf("%s",str)!=EOF)
 {
  int len=strlen(str);
  int flag=0;
  for(i=0;i<len;i++)
  {
    a[i]=0;
   switch(str[i])
   {
    case 'B':
    case 'F':
    case 'P':
    case 'V':
       a[i]=1;
       break;
    case 'C':
    case 'G':
    case 'J':
    case 'K':
    case 'Q':
    case 'S':
    case 'X':
    case 'Z':
       a[i]=2;
        break;
    case 'D':
    case 'T':
       a[i]=3;
        break;
    case 'L':
       a[i]=4;
        break;
    case 'M':
    case 'N':
       a[i]=5;
        break;
    case 'R':
       a[i]=6;
        break;
    case 'A':
    case 'E':
    case 'I':
    case 'O':
    case 'U':
    case 'H':
    case 'W':
    case 'Y':
       a[i]=0;
        break;
    default:
        break;
    }
   }
  for(i=0;i<len;i++)
  {
  if(!(a[i]==0||a[i]==a[i-1])) 
  {
      flag=1;
      printf("%d",a[i]);
  }
   }
  if(flag)
      printf("\n");
  }
// system("pause");
  return 0;
 }

回复列表 (共1个回复)

沙发

我运行了你的程序没有什么错误啊
我用GCC编译的

我来回复

您尚未登录,请登录后再回复。点此登录或注册