poj 2608 Soundex

#include <stdio.h>
char ch[20];
	
int Find(int i)
{
	while(1)
	{
	  if (ch[i]==ch[i+1]) i++;
	  else if(ch[i]!=ch[i+1]) return i;
	}
}
int main(int argc, char *argv[])
{
	int i;

	while(scanf("%s",ch)!=EOF)
	{
		for (i=0;ch[i];i++)
		{
			switch(ch[i])
			{
				case'B':
				case'F':
				case'P':
				case'V':ch[i]='1';break;
				case'C':
				case'G':
				case'J':
				case'K':
				case'Q':
				case'S':
				case'X':
				case'Z':ch[i]='2';break;
				case'D':
				case'T':ch[i]='3';break;
				case'L':ch[i]='4';break;
				case'M':
				case'N':ch[i]='5';break;
				case'R':ch[i]='6';
			}
		}
			for(i=0;ch[i];i++)
			{
				i=Find(i);
				if(ch[i]>='1' && ch[i]<='6') printf("%c",ch[i]);
			}
		printf("\n");
	}
	return 0;
}


 题意:

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

Sample Input

KHAWN
PFISTER
BOBBY

Sample Output

25
1236
11

邻接的两个代表的数字一样的话就输出一个

 

你可能感兴趣的:(poj 2608 Soundex)