google在线测试练习题3

本文介绍了一种通过按键组合来简化短信中字符输入的方法,利用拉丁字母与电话键盘按键之间的对应关系,使得发送消息更为便捷。对于连续输入相同字符的情况,文中提出在按键两次前暂停的操作,同时为空格字符提供了特殊的输入方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

#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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值