google在线測试练习题3
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.
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
int n_case;
ifstream ifile("C-large-practice.in");
ofstream ofile("result_c2.txt");
ifile >> n_case;
int reference[26] = {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
int replace[26] = {2,22,222,3,33,333,4,44,444,5,55,555,6,66,666,7,77,777,7777,8,88,888,9,99,999,9999};
for(int i = 0; i <= n_case; i++)
{
char line[1002];
ifile.getline(line, 1002);
string words(line);
if(i == 0)
continue;
ofile << "Case #" << i << ": ";
for(int i = 0; i < words.length(); i++)
{
if(words[i] == ' ')
{
if(i - 1 >= 0 && words[i - 1] == ' ')
ofile << ' ' << 0;
else ofile << 0;
}
else
{
if(i - 1 >= 0 && reference[words[i] - 'a'] == reference[words[i - 1] - 'a'])
ofile << ' ' << replace[words[i] - 'a'];
else ofile << replace[words[i] - 'a'];
}
}
ofile << endl;
}
return 0;
}
google在线測试练习题3的更多相关文章
- google在线測试练习题1
Problem You receive a credit C at a local store and would like to buy two items. You first walk thro ...
- go五笔——基于Google在线五笔制作
go五笔 v0.0.2 加入新世纪版 86版收录几个不常用汉字,其它无更新 下载 86版64位密码: qe7k 86版32位密码: y25a 06版64位密码: d2ug 06版32位密码: bxxz ...
- [华为机试练习题]55.最大公约数 & 多个数的最大公约数
题目 描写叙述: 输入2个数字,最后输出2个数字的最大公约数 题目类别: 位运算 难度: 0基础 执行时间限制: 无限制 内存限制: 无限制 阶段: 入职前练习 输入: 2个整数 输出: 输出数字1和 ...
- [华为机试练习题]50.求M的N次方的最后三位
题目 描写叙述: 正整数M 的N次方有可能是一个很大的数字,我们仅仅求该数字的最后三位 例1: 比方输入5和3 ,5的3次方为125.则输出为125 例2: 比方输入2和10 2的10次方为1024 ...
- jsfiddle在线測试Html、CSS、JavaScript——http://jsfiddle.net/
jsfiddle在线測试Html.CSS.JavaScript,并展示測试结果 1.选择jQuery1.9.1 2.选择jQuery UI 1.9.2 3.Html <ul id="n ...
- Google Code Jam在线測试题目--Alien Language
Problem After years of study, scientists at Google Labs have discovered an alien language transmitte ...
- google校招在线測试题---2048
先附代码:(简单地说就是给出一个矩阵代表2048游戏的一个状态以及一个方向,输出往这个方向移动之后的矩阵) #include<iostream> #include<fstream&g ...
- google 在线代理浏览
谷歌访问不了,你又N多方法,比如搭建VPN,买VPN,或查找google多个IP访问, 或通过第三方反代理网站访问, 或通过客户端代理(类似goagent)等 下面罗列出可以访问google的几个代理 ...
- 免费APP在线測试工具以及其用法
免费APP漏洞安全检測工具:http://safe.ijiami.cn/ 漏洞分析是爱加密推出免费 APP 漏洞分析平台,服务包含一键对APK 进行签名数据信息採集.内部配置信息採集.市场渠道相关信息 ...
随机推荐
- Django REST Framework - 分页 - 渲染器 - 解析器
为什么要使用分页? 我们数据表中可能会有成千上万条数据,当我们访问某张表的所有数据时,我们不太可能需要一次把所有的数据都展示出来,因为数据量很大,对服务端的内存压力比较大还有就是网络传输过程中耗时也会 ...
- HDOJ 5294 Tricks Device 最短路(记录路径)+最小割
最短路记录路径,同一时候求出最短的路径上最少要有多少条边, 然后用在最短路上的边又一次构图后求最小割. Tricks Device Time Limit: 2000/1000 MS (Java/Oth ...
- python解压,压缩,以及存数据库的相关操作
zipfile实现压缩整个目录和子目录 import os,shutil,zipfile,glob def dfs_get_zip_file(input_path,result): # files = ...
- iOS-UITextField 全面解析
iOS中UITextField 使用全面解析 建议收藏,用到的时候来这里一查就都明白了 //初始化textfield并设置位置及大小 UITextField *text = [[UITextField ...
- ES 遇到 unassigned shard如何处理?
解决方法:(1)如果是红色的,可以直接分片shard给你认为有最新(或最多)数据的节点.见下: 摘自:https://discuss.elastic.co/t/how-to-resolve-the-u ...
- Redis-3-string类型
Redis-3-string类型 标签(空格分隔): redis set key value [ex 秒数] / [px 毫秒数] [nx] /[xx] mset key value key valu ...
- node,koa 图片批量添加水印,可手动配置水印位置
公司设计在处理京东上架商品图片的时候,需要给设计好的图片添加京东的“logo”,并且logo位置得根据图片来摆放,需要通过计算得出logo位置.那样太麻烦了,于是就用node,koa写了批量给图片添加 ...
- Re:从 0 开始的微服务架构--(三)微服务架构 API 的开发与治理--转
原文来自:聊聊架构公众号 前面的文章中有说到微服务的通信方式,Martin Folwer 先生在他对微服务的定义中也提到“每个服务运行在其独立的进程中,服务与服务间采用 轻量级的通信机制 互相协作(通 ...
- Kotlin 中文文档
Kotlin 中文文档 标签: Kotlinkotlin中文文档 2017-02-14 18:14 4673人阅读 评论(0) 收藏 举报 分类: kotlin 转载地址:http://www.tu ...
- STM8S103之时钟设置
最大时钟(指的是system clock):外部晶振24MHz,内部高速RC16MHz 三个时钟源:外部晶振.内部高速RC(上电默认) +内部低速RC 几个时钟:master clock(即sytem ...