(code jam)Problem C. T9 Spelling

本文详细介绍了如何使用手机输入法将字母映射到按键组合,并解释了如何通过按键和空格符号来输入文本。重点在于理解同一按键两次输入之间的停顿表示,以及特殊字符的输入方式。

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 

Output 
4
hi
yes
foo  bar
hello world

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

题意就是如题,应该不看都能看懂,就是平常手机输入法,注意空格用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;
					
				}
				else
				if (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;
}



<think>好的,我现在需要帮助用户解决关于&#39;##TEXT_POOL&#39;未定义的错误。首先,我应该理解这个错误通常出现在什么情况下。根据经验,这类错误通常与预处理器或宏定义有关,尤其是在C/C++代码中。用户可能在使用某个宏或变量时没有正确声明它。 接下来,我需要查阅用户提供的引用内容,看看是否有相关线索。引用[4]提到了内存池的实现,可能涉及到内存分配的操作,比如使用g_ptrMemPool来获取和释放内存。如果用户代码中使用了类似TEXT_POOL的结构,但没有正确初始化或定义,就会导致这个错误。 然后,我应该考虑常见的解决方案。首先检查是否正确定义了TEXT_POOL,比如头文件是否包含,或者是否有拼写错误。如果使用外部库,可能需要链接相应的库文件。此外,如果TEXT_POOL是一个宏,确保它在使用前已经被定义,并且作用域正确。 另外,用户可能在代码中错误地使用了##操作符,这在宏定义中用于连接令牌,但如果使用不当,比如在未定义的宏前使用,会导致&#39;##TEXT_POOL&#39;这样的错误。需要检查宏定义的语法是否正确。 还需要考虑代码中是否存在作用域问题,比如在某个函数内部定义而外部无法访问。或者,如果TEXT_POOL是全局变量,是否在多个文件中正确声明为extern。 最后,建议用户提供更多代码片段,特别是出现错误的位置,以便更准确地诊断问题。同时,建议检查编译器的文档,了解关于宏和预处理器错误的更多信息,确保所有依赖项都已正确安装和配置。</think>关于&#39;##TEXT_POOL&#39;未定义错误的解决方案: ### 错误原因分析 1. **预处理器宏错误**:双井号`##`在C/C++中用于宏的令牌连接操作,但需要确保连接对象已定义 2. **变量/对象未声明**:TEXT_POOL可能是一个内存池对象或宏定义,未在作用域内声明 3. **作用域问题**:变量定义在特定代码块中无法被其他模块访问 4. **头文件缺失**:未包含定义TEXT_POOL的库头文件 ### 分步解决方案 1. **检查宏定义语法**: ```c // 正确用法示例 #define CREATE_POOL(name) g_##name##_pool CREATE_POOL(TEXT); // 展开为g_TEXT_pool ``` 若不需要令牌连接操作,应移除多余的`##`符号 2. **验证内存池初始化**(参考引用[4]): ```c // 确保在使用前已创建内存池对象 MemoryPool* TEXT_POOL = new MemoryPool(1024); // 显式实例化 // 或使用全局访问器 MemoryPool* GetTextPool() { static MemoryPool instance(1024); return &instance; } ``` 3. **检查头文件包含**: ```c // 添加包含内存池定义的头部 #include "memory_pool.h" // 定义TEXT_POOL的声明 #include <external_lib/text_processing.h> // 可能定义该符号的第三方库 ``` 4. **确认链接依赖**: ```makefile # 在Makefile中确保链接相关库 LDFLAGS += -ltext_pool -lmem_alloc ``` ### 常见错误模式 1. **拼写错误**:检查`TEXT_POOL`与`TEXTPOOL`的大小写和下划线一致性 2. **生命周期问题**:若为静态对象,需确保初始化顺序正确 3. **平台差异**:Windows系统可能需要`__declspec(dllimport)`声明 ### 调试建议 1. 使用预处理器输出验证: ```bash gcc -E main.c -o main.i # 查看预处理后的代码 ``` 2. 检查符号表: ```bash nm -gC build/object_file.o | grep TEXT_POOL ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值