博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2608 Soundex(我的水题之路——字符值)
阅读量:4069 次
发布时间:2019-05-25

本文共 2322 字,大约阅读时间需要 7 分钟。

Soundex
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8200   Accepted: 4039

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

KHAWNPFISTERBOBBY

Sample Output

25123611

Source

26个字母分别对应了不同的值,现在给一个字符串,按照如下规则输出:

1)如果字母有值,则考虑输出;否则不输出。

2)多个拥有相同值的字母并列,仅输出一个值。

直接比较,如果对每一个字符进行取值,取上一次不同字符值的值last,进行比较,如果本字符有值(不为0),且不同于上一次的值last,就输出其值。

注意点:

1)注意打表正确(1WA)。

2)无论这个值是否输出,皆保存本次值为last。

代码(1AC 1WA):

#include 
#include
#include
char str[30];int arr[50];void init(){ arr[0] = 0; // A arr[1] = 1; // B arr[2] = 2; // C arr[3] = 3; // D arr[4] = 0; // E arr[5] = 1; // F arr[6] = 2; // G arr[7] = 0; // H arr[8] = 0; // I arr[9] = 2; // J arr[10] = 2; // K arr[11] = 4; // L arr[12] = 5; // M arr[13] = 5; // N arr[14] = 0; // O arr[15] = 1; // P arr[16] = 2; // Q arr[17] = 6; // R arr[18] = 2; // S arr[19] = 3; // T arr[20] = 0; // U arr[21] = 1; // V arr[22] = 0; // W arr[23] = 2; // X arr[24] = 0; // Y arr[25] = 2; // Z}int main(void){ char last, tmp; int len, i; init(); while (scanf("%s", str) != EOF){ len = strlen(str); last = 0; for (i = 0; i < len ; i++){ if (arr[str[i] - 'A'] != 0 && arr[str[i] - 'A'] != last){ printf("%d", (last = arr[str[i] - 'A'])); } else{ last = arr[str[i] - 'A']; } } printf("\n"); } return 0;}

注意点:

转载地址:http://eooji.baihongyu.com/

你可能感兴趣的文章
do_generic_file_read()函数
查看>>
Python学习笔记之数据类型
查看>>
Python学习笔记之特点
查看>>
Python学习笔记之安装
查看>>
shell 快捷键
查看>>
VIM滚屏操作
查看>>
EMC 2014存储布局及十大新技术要点
查看>>
linux内核内存管理(zone_dma zone_normal zone_highmem)
查看>>
将file文件内容转成字符串
查看>>
循环队列---数据结构和算法
查看>>
优先级队列-数据结构和算法
查看>>
链接点--数据结构和算法
查看>>
servlet中请求转发(forword)与重定向(sendredirect)的区别
查看>>
Spring4的IoC和DI的区别
查看>>
springcloud 的eureka服务注册demo
查看>>
eureka-client.properties文件配置
查看>>
MODULE_DEVICE_TABLE的理解
查看>>
platform_device与platform_driver
查看>>
platform_driver平台驱动注册和注销过程(下)
查看>>
.net强制退出主窗口的方法——Application.Exit()方法和Environment.Exit(0)方法
查看>>