(code jam)Problem C. T9 Spelling
来源:互联网 发布:vpn软件哪个好 编辑:程序博客网 时间:2024/05/16 17:43
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, N. N 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
题意就是如题,应该不看都能看懂,就是平常手机输入法,注意空格用0输出,相同数字就用空格输出。
结果大数据纠结在上一次输入的也要记录!也就是说上一次输入比如是yes 后一次输入sk。那个s也继承上一次输入的s,要输出一个空格!!!坑啊。。。
#include <iostream>#include <cmath>#include <cstring>using namespace std;int main(){int t,i,j;char s[10100];freopen("C-large-practice.in","r",stdin);freopen("output.out","w",stdout);scanf("%d",&t);getchar();int qq=0;int k=0;while (t--){printf("Case #%d: ",++qq);gets(s);int l=strlen(s);for (i=0;i<l;i++){j=0;if (s[i]==' ') {if (j==k) printf(" ");k=0;printf("0");continue;}j=s[i]-'a'+1;int y;if (j<=15){y=(j-1)%3;j=ceil(j*1.0/3);j++;}else{if (j<=19) {y=j-16;j=7;}elseif (j<=22){y=j-20;j=8;}else{y=j-23;j=9;}}if (j==k) printf(" ");k=j;for (int h=0;h<=y;h++)printf("%d",j);}printf("\n");}return 0;}
- (code jam)Problem C. T9 Spelling
- T9 Spelling-GOOGLE CODE JAM AFICA 2010 Qualification Round
- (code jam)Problem C. Numbers
- T9 Spelling
- Google Code Jam 2010 Qualification Round 2012 Problem B && C
- Code Jam 2010 Round 1A Problem C
- Code Jam 2010 Round 1B Problem C
- Google Code Jam 2014 Problem C. Minesweeper Master
- Google Code Jam 2014-Qualification Round-Problem C. Minesweeper Master
- Google Code Jam 2015 Qualification Round: Problem C. Dijkstra
- google code jam Round 1A 2015 Problem C. Logging
- code jam 2015 Problem C. Less Money, More Problems
- Code Jam 2017 Qualification Round Problem C. Bathroom Stalls
- Code Jam Problem D. GoroSort
- Google Code Jam 2014 -- C
- Google code jam Round1B Problem B
- Google code jam: Problem A. Store Credit
- Google code jam: Problem B. Reverse Words
- Java中使用JDBC访问MySQL数据库
- 在字符串后面添加数字变成一个新的字符串或者将一个字符串分割为多个的代码
- 简单的数组
- 南阳 212 k尾数相等
- Android声明周期
- (code jam)Problem C. T9 Spelling
- oracle :性能优化的一个案例查找CPU 过高
- 破坏描述符memory应用举例
- Hadoop 2.2 & HBase 0.96 Maven 依赖总结
- ll命令
- hdu2444(二分图判定+二分图匹配)
- java基础之选择排序
- Android中的风格和主题(style和theme)
- 今后学习计划