# PAT 解题报告 1061. Dating (20)

### 题目描述：

Sherlock Holmes received a note with some strange strings: “Let’s date! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm”. It took him only a minute to figure out that those strange strings are actually referring to the coded time “Thursday 14:04″ — since the first common capital English letter (case sensitive) shared by the first two strings is the 4th capital letter ‘D’, representing the 4th day in a week; the second common character is the 5th capital letter ‘E’, representing the 14th hour (hence the hours from 0 to 23 in a day are represented by the numbers from 0 to 9 and the capital letters from A to N, respectively); and the English letter shared by the last two strings is ‘s’ at the 4th position, representing the 4th minute. Now given two pairs of strings, you are supposed to help Sherlock decode the dating time.

### 算法分析：

PAT的题目描述真心不敢恭维, 十分的fuzzy. 题目要求对应的三个时间.

(1) 求日期(周一到周日的其中一天): 题目中说是找到前面两个字符串中的第一个公共的大些字母, 这个大些字母是第几个, 那就是星期几. 比如D是第四个, 那么就是星期四. 可是如果这个公共相同的大写字母是Z之类的呢? 然后模7么? 这里题目没说, 所以不要自己加规则(模7), 最后的结论是： 找到第一个相同的A-G(1-7)的大写字母, 其他的跳过.

(2) 求小时: 这个题目就说的更加不清楚了, 反正我是理解了半天, 题目说是第二对相同的字符, 所以应该是从(1)中那对相同的字符开始搜, 搜到第一对(gloabl来讲这个就是第二对了)相同的A-N, 0-9的字符, 取这个计算0-23小时的值.

(3) 求分钟: 这个基本没有问题, 找到后面两个字符串的第一对相同的英文字符(小写和大写都算), 返回这个字符的index就可以了.

### 注意点：

（全文完，原创文章，转载时请注明作者和出处）

（转载本站文章请注明作者和出处 烟客旅人 sigmainfy — http://www.sigmainfy.com，请勿用于任何商业用途）

Written on September 2, 2013