T9

Description

Background

A while ago it was quite cumbersome to create a message for the Short Message Service (SMS) on a mobile phone. This was because you only have nine keys and the alphabet has more than nine letters, so most characters could only be entered by pressing one key several times. For example, if you wanted to type "hello" you had to press key 4 twice, key 3 twice, key 5 three times, again key 5 three times, and finally key 6 three times. This procedure is very tedious and keeps many people from using the Short Message Service.

This led manufacturers of mobile phones to try and find an easier way to enter text on a mobile phone. The solution they developed is called T9 text input. The "9" in the name means that you can enter almost arbitrary words with just nine keys and without pressing them more than once per character. The idea of the solution is that you simply start typing the keys without repetition, and the software uses a built-in dictionary to look for the "most probable" word matching the input. For example, to enter "hello" you simply press keys 4, 3, 5, 5, and 6 once. Of course, this could also be the input for the word "gdjjm", but since this is no sensible English word, it can safely be ignored. By ruling out all other "improbable" solutions and only taking proper English words into account, this method can speed up writing of short messages considerably. Of course, if the word is not in the dictionary (like a name) then it has to be typed in manually using key repetition again.

Figure 8: The Number-keys of a mobile phone.

More precisely, with every character typed, the phone will show the most probable combination of characters it has found up to that point. Let us assume that the phone knows about the words "idea" and "hello", with "idea" occurring more often. Pressing the keys 4, 3, 5, 5, and 6, one after the other, the phone offers you "i", "id", then switches to "hel", "hell", and finally shows "hello".

Problem

Write an implementation of the T9 text input which offers the most probable character combination after every keystroke. The probability of a character combination is defined to be the sum of the probabilities of all words in the dictionary that begin with this character combination. For example, if the dictionary contains three words "hell", "hello", and "hellfire", the probability of the character combination "hell" is the sum of the probabilities of these words. If some combinations have the same probability, your program is to select the first one in alphabetic order. The user should also be able to type the beginning of words. For example, if the word "hello" is in the dictionary, the user can also enter the word "he" by pressing the keys 4 and 3 even if this word is not listed in the dictionary.
Input

The first line contains the number of scenarios.

Each scenario begins with a line containing the number w of distinct words in the dictionary (0<=w<=1000). These words are iven in the next w lines in ascending alphabetic order. Every line starts with the word which is a sequence of lowercase letters from the alphabet without whitespace, followed by a space and an integer p, 1<=p<=100, representing the probability of that word. No word will contain more than 100 letters.

Following the dictionary, there is a line containing a single integer m. Next follow m lines, each consisting of a sequence of at most 100 decimal digits 2�, followed by a single 1 meaning "next word".
Output

The output for each scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1.

For every number sequence s of the scenario, print one line for every keystroke stored in s, except for the 1 at the end. In this line, print the most probable word prefix defined by the probabilities in the dictionary and the T9 selection rules explained above. Whenever none of the words in the dictionary match the given number sequence, print "MANUALLY" instead of a prefix.

Terminate the output for every number sequence with a blank line, and print an additional blank line at the end of every scenario.
Sample Input

2
5
hell 3
hello 4
idea 8
next 8
super 3
2
435561
43321
7
another 5
contest 6
give 13
integer 6
new 14
program 4
5
77647261
6391
4681
26684371
77771
Sample Output

Scenario #1:
i
id
hel
hell
hello

i
id
ide
idea

Scenario #2:
p
pr
pro
prog
progr
progra
program

n
ne
new

g
in
int

c
co
con
cont
anoth
anothe
another

p
pr
MANUALLY
MANUALLY

1个回答

PHP T9手机键盘[关闭]

<div class="post-text" itemprop="text"> <p>I have just started PHP programming and have the following scenario;</p> <ol> <li>My contact list is saved in mysql database (Fname, Lname, phone) = done </li> <li>Take user input as imagining it taking from a mobile keypad .i.e. 'abc' corresponds to 1, 'def corresponds to 2 etc.</li> <li>Let's say user enters "738"...this would correspond to 'PET' and so will 'REU'. </li> <li>What the php code is suppose to do is get the user input in the form of digits and search through the mysql database going through the last name to see if it corresponds to any of the name and finally list those contact(s). However, since 'SET' is also a valid combination of 738 BUT if it does not exist in the database, it will not get displayed.</li> </ol> <p>Question: how can i take the input in digits and generate all possible combination to match against the database? I guess i will have to use arrays to store the mobile keypad mapping and somehow do the permutations stuff. Any help will be appreciated.</p> </div>

k8s挂载ceph失败，pod状态一直是ContainerCreating

Base64解码图像字符串

Mysql替换了像+这样的特殊字符

PHP电子邮件附件未通过

jsoup抓取dopostback的网页错误 ,是不是BODY出什么问题

<div class="post-text" itemprop="text"> <p>I have the following mysql query. How can i make the result of the query be a new table;</p> <pre><code>SELECT t1.referree AS LEVEL1, t2.referree AS LEVEL2, t3.referree AS LEVEL3, t4.referree AS LEVEL4, t5.referree AS LEVEL5, t6.referree AS LEVEL6, t7.referree AS LEVEL7, t8.referree AS LEVEL8, t9.referree AS LEVEL9, t10.referree LEVEL10, t11.referree AS LEVEL11 FROM referrals AS t1 LEFT JOIN referrals AS t2 ON t2.referrer = t1.referree LEFT JOIN referrals AS t3 ON t3.referrer = t2.referree LEFT JOIN referrals AS t4 ON t4.referrer = t3.referree LEFT JOIN referrals AS t5 ON t5.referrer = t4.referree LEFT JOIN referrals AS t6 ON t6.referrer = t5.referree LEFT JOIN referrals AS t7 ON t7.referrer = t6.referree LEFT JOIN referrals AS t8 ON t8.referrer = t7.referree LEFT JOIN referrals AS t9 ON t9.referrer = t8.referree LEFT JOIN referrals AS t10 ON t10.referrer = t9.referree LEFT JOIN referrals AS t11 ON t11.referrer = t10.referree WHERE t1.referrer ='2')); </code></pre> </div>

<div class="post-text" itemprop="text"> <p><a href="http://sqlfiddle.com/#!9/c864c4/6" rel="nofollow">SQL FIDDLE</a></p> <p>I want to select from a few table only if they dont exist in another table my select query is like this</p> <pre><code>SELECT * ,t1.pin AS table1_pin ,t3.pin AS table2_pin ,t6.pin AS table3_pin ,t9.pin AS table4_pin ,t2.tin AS table1_tin ,t2.first_name AS table1_firstname ,t2.last_name AS table1_lastname ,t2.middle_name AS table1_middlename ,t2.suffix AS table1_suffix ,t5.tin AS table2_tin ,t5.first_name AS table2_firstname ,t5.last_name AS table2_lastname ,t5.middle_name AS table2_middlename ,t5.suffix AS table2_suffix ,t8.tin AS table3_tin ,t8.first_name AS table3_firstname ,t8.last_name AS table3_lastname ,t8.middle_name AS table3_middlename ,t8.suffix AS table3_suffix ,t10.tin AS table4_tin ,t10.first_name AS table4_firstname ,t10.last_name AS table4_lastname ,t10.middle_name AS table4_middlename ,t10.suffix AS table4_suffix ,t1.effectivity_qtr AS table1qtr ,t1.effectivity_year AS table1year ,t4.effectivity_qtr AS table2qtr ,t4.effectivity_year AS table2year ,t7.effectivity_qtr AS table3qtr ,t7.effectivity_year AS table3year ,t9.effectivity_qtr AS table4qtr ,t9.effectivity_year AS table4year FROM table1 AS t1 LEFT JOIN table1_ AS t2 ON t1.pin = t2.pin AND t1.status = t2.status LEFT JOIN table2 AS t3 ON t1.pin= t3.table2_pin AND t1.status = t3.status LEFT JOIN table2_ AS t4 ON t3.pin = t4.pin AND t3.status = t4.status LEFT JOIN table2__ AS t5 ON t3.pin = t5.pin AND t3.status = t5.status LEFT JOIN table3 AS t6 ON t1.pin = t6.table3_pin AND t1.status = t6.status LEFT JOIN table3__ AS t7 ON t6.pin = t7.pin AND t6.status = t7.status LEFT JOIN table3_ AS t8 ON t6.pin = t8.pin AND t6.status = t8.status LEFT JOIN table4 AS t9 ON t1.pin = t9.pin AND t1.status = t9.status LEFT JOIN table4_ AS t10 ON t1.pin = t10.pin AND t1.status = t10.status WHERE t1.pin LIKE '%1%' AND NOT EXISTS ( SELECT * FROM tablep1 AS tp1 WHERE ( tp1.pin = t1.pin AND tp1.year = t1.effectivity_year) OR (tp1.pin = t4.pin AND tp1.year = t4.effectivity_year) OR (tp1.pin = t7.pin AND tp1.year = t7.effectivity_year) OR (tp1.pin = t9.pin AND tp1.year = t9.effectivity_year)) AND t1.status = 'Active' </code></pre> <p>I just want to select from <code>table tables</code> only if the pin number is not present in <code>tablep1 table</code></p> <p>Any suggestion is appreciated</p> </div>

“亚马逊丛林里的蝴蝶扇动几下翅膀就可能引起两周后美国德州的一次飓风……” 这句人人皆知的话最初用来描述非线性系统中微小参数的变化所引起的系统极大变化。 而在更长的时间尺度内，我们所生活的这个世界就是这样一个异常复杂的非线性系统…… 水泥、穹顶、透视——关于时间与技艺的蝴蝶效应 公元前3000年，古埃及人将尼罗河中挖出的泥浆与纳特龙盐湖中的矿物盐混合，再掺入煅烧石灰石制成的石灰，由此得来了人...

loonggg读完需要3分钟速读仅需 1 分钟大家好，我是你们的校长。我之前讲过，这年头，只要肯动脑，肯行动，程序员凭借自己的技术，赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

MySQL数据库面试题（2020最新版）

HashMap底层实现原理，红黑树，B+树，B树的结构原理 Spring的AOP和IOC是什么？它们常见的使用场景有哪些？Spring事务，事务的属性，传播行为，数据库隔离级别 Spring和SpringMVC，MyBatis以及SpringBoot的注解分别有哪些？SpringMVC的工作原理，SpringBoot框架的优点，MyBatis框架的优点 SpringCould组件有哪些，他们...

《经典算法案例》01-08：如何使用质数设计扫雷（Minesweeper）游戏

《Oracle Java SE编程自学与面试指南》最佳学习路线图（2020最新版）