博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Google APAC----Africa 2010, Qualification Round(Problem C. T9 Spelling)----Perl 解法
阅读量:7212 次
发布时间:2019-06-29

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

原题地址链接:

问题描述:

Problem

The Latin alphabet contains 26 characters and telephones only have ten digits on the keypad. We would like to make it easier to write a message to your friend using a sequence of keypresses to indicate the desired characters. The letters are mapped onto the digits as shown below. To insert the character B for instance, the program would press22. In order to insert two characters in sequence from the same key, the user must pause before pressing the key a second time. The space character ' ' should be printed to indicate a pause. For example, 2 2 indicates AA whereas 22 indicates B.

Input

The first line of input gives the number of cases, NN test cases follow. Each case is a line of text formatted as

desired_message

Each message will consist of only lowercase characters a-z and space characters ' '. Pressing zero emits a space.

Output

For each test case, output one line containing "Case #x: " followed by the message translated into the sequence of keypresses.

Limits

1 ≤ N ≤ 100.

Small dataset

1 ≤ length of message in characters ≤ 15.

Large dataset

1 ≤ length of message in characters ≤ 1000.

 

Sample

Input 4hiyesfoo  barhello worldOutput Case #1: 44 444Case #2: 999337777Case #3: 333666 6660 022 2777Case #4: 4433555 555666096667775553

 

Perl算法:

1 #!/usr/bin/perl  2 my $debug=0; #该问题略微复杂,所以使用调试技术:如果$debug为1,则结果显示在标准输出上,而不输出到 .out 文件内;如果$debug 为0,则结果直接输出到 .out 文件中。  3 my $infile='C-large-practice.in';  4 my $outfile='C-large.out';  5 open $in,'<',$infile  6         or die "Cannot open $infile:$!\n";  7 open $out,'>',$outfile  8         or die "Cannot open $outfile:$!\n";  9 #建立哈希表 10 my %dict=( 11         2=>"abc", 12         3=>"def", 13         4=>"ghi", 14         5=>"jkl", 15         6=>"mno", 16         7=>"pqrs", 17         8=>"tuv", 18         9=>"wxyz", 19         0=>" " 20 ); 21  22 if($debug){ 23         for(keys %dict){ 24                 print "$_=>'$dict{$_}'\n"; 25         } 26 } 27 chomp(my $N=<$in>); 28 my $str; 29 my $line; 30 my $prev,$cur; 31 $N=5 if $debug; 32 for($i=1;$i<=$N;$i++){ 33         $str=""; 34         $prev=""; 35         chomp($line=<$in>); 36         my $temp=""; 37         print "===================== For \$line='$line' =======================:\n" if $debug; 38         print "length($line)=",length($line),"\n" if $debug; 39         for(my $index=0;$index

 

 

上传原题地址链接网站,结果正确。

 

转载于:https://www.cnblogs.com/dongling/p/5707004.html

你可能感兴趣的文章
大数据会如何影响VC领域?
查看>>
人力资源SaaS软件“乐才Joy HR”获数百万元战略融资
查看>>
借攻防演习提升企业安全能力
查看>>
美国国土安全部发布物联网安全最佳实践
查看>>
迅游科技拟作价27亿元收购移动应用开发商狮之吼
查看>>
最新桌面操作系统份额统计:Windows占比91.59%
查看>>
华平助广东海事局构建水上搜救应急指挥系统
查看>>
投资数据中心所考虑的重要因素
查看>>
第一太阳能公司(First Solar)在罗斯资本公司的评级上调
查看>>
德国软件巨头SAP旗下风投基金募集10亿美元 专门投资科技初创公司
查看>>
保险报业携手万丈金数 探索大数据应用升级
查看>>
诺基亚正式收购阿朗:物联网时代再出发
查看>>
SAP Business One助力洛德集团实现巨大商业价值
查看>>
单晶组件的平价上网路线
查看>>
路由器LED闪灯泄露数据
查看>>
微软公司将在英国开设三个数据中心
查看>>
解析弱电安防监控管理系统的安装技术重点
查看>>
Oracle新一代数据库机 助所有规模企业迈向云端
查看>>
2017年中国大功率UPS市场需求、市场需求及市场结构占比分析预测
查看>>
三星集团总市值达3220亿美元,高阿里巴巴近千亿
查看>>