HDU 1075(What Are You Talking About-Trie的插入和查找)

本文深入探讨了AI音视频处理领域中的关键技术,特别是视频分割与语义识别,详细解释了如何利用这些技术实现更智能的音视频应用。

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

What Are You Talking About

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K (Java/Others)
Total Submission(s): 8571    Accepted Submission(s): 2696


Problem Description
Ignatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leaves. Now Ignatius want to translate the history book into English. Can you help him?
 

Input
The problem has only one test case, the test case consists of two parts, the dictionary part and the book part. The dictionary part starts with a single line contains a string "START", this string should be ignored, then some lines follow, each line contains two strings, the first one is a word in English, the second one is the corresponding word in Martian's language. A line with a single string "END" indicates the end of the directory part, and this string should be ignored. The book part starts with a single line contains a string "START", this string should be ignored, then an article written in Martian's language. You should translate the article into English with the dictionary. If you find the word in the dictionary you should translate it and write the new word into your translation, if you can't find the word in the dictionary you do not have to translate it, and just copy the old word to your translation. Space(' '), tab('\t'), enter('\n') and all the punctuation should not be translated. A line with a single string "END" indicates the end of the book part, and that's also the end of the input. All the words are in the lowercase, and each word will contain at most 10 characters, and each line will contain at most 3000 characters.
 

Output
In this problem, you have to output the translation of the history book.
 

Sample Input
START from fiwo hello difh mars riwosf earth fnnvk like fiiwj END START difh, i'm fiwo riwosf. i fiiwj fnnvk! END
 

Sample Output
hello, i'm from mars. i like earth!
Hint
Huge input, scanf is recommended.
 

Author
Ignatius.L
 

Trie的插入和查找

话说也不难啊……

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<cstdlib>
#include<iostream>
#include<cctype>
using namespace std;
#define MAXWordlen (10+10)
#define MAXLen (3000+10)
char s[MAXLen];
char word[MAXWordlen],word1[MAXWordlen];
struct node
{
	node *next[26+1];
	char t[MAXWordlen];
	node()
	{
		t[0]=0;
		for (int i=0;i<=26;i++) next[i]=NULL;
	}
}root;
void insert(char *str,char str1[])
{
	int len=strlen(str);
	node *p=&root;
	for (int i=0;i<len;i++)
	{
		if (p->next[str[i]-'a']==NULL) p->next[str[i]-'a']=new node();
		p=p->next[str[i]-'a'];		
	}
	strcpy(p->t,str1);
}
node* find(int l,int r)
{
	node *p=&root;
	for (int i=l;i<=r;i++)
	{
		if (p->next[s[i]-'a']==NULL) return 0;
		p=p->next[s[i]-'a'];		
	}
	if (strcmp(p->t,"")) return p;	
	return 0;
}
int main()
{
	scanf("START");
	while (scanf("%s",word)&&strcmp(word,"END"))
	{
		scanf("%s",word1);
		insert(word1,word);
	}
	gets(word);
	scanf("START");
	gets(word);
	while (gets(s))
	{
		if (!strcmp(s,"END")) break; 
		int len=strlen(s);
		s[len+1]=0;
		for (int i=0;i<len;i++)
		{
			if (islower(s[i]))
			{
				int j=i;
				while (islower(s[j+1])) j++;
				node *p=find(i,j);
				if (p) printf("%s",p->t);
				else
				{
					for (int k=i;k<=j;k++) printf("%c",s[k]);
				} 
				i=j;				 
			}
			else printf("%c",s[i]);
		}
		printf("\n");
	}
	return 0;
}

HDU 2034 是一道经典的 A-B Problem 题目,通常涉及简单的数学运算或者字符串处理逻辑。以下是对此类问题的分析以及可能的解决方法。 ### HDU 2034 的题目概述 该题目要求计算两个数之间的差值 \(A - B\) 并输出结果。需要注意的是,输入数据可能存在多种情况,因此程序需要能够适应不同的边界条件特殊情况[^1]。 #### 输入描述 - 多组测试数据。 - 每组测试数据包含两行,分别表示整数 \(A\) \(B\)。 #### 输出描述 对于每组测试数据,输出一行表示 \(A - B\) 的结果。 --- ### 解决方案 此类问题的核心在于正确读取多组输入并执行减法操作。以下是实现此功能的一种常见方式: ```python while True: try: a = int(input()) b = int(input()) print(a - b) except EOFError: break ``` 上述代码片段通过循环不断接收输入直到遇到文件结束符 (EOF),适用于批量处理多组测试数据的情况。 --- ### 特殊考虑事项 尽管基本思路简单明了,在实际编码过程中仍需注意以下几点: 1. **大数值支持**:如果题目中的 \(A\) 或 \(B\) 可能非常大,则应选用可以容纳高精度的数据类型来存储这些变量。 2. **负数处理**:当 \(B>A\) 导致结果为负时,确保程序不会因符号错误而失效。 3. **异常捕获**:为了防止运行期间由于非法字符或其他意外状况引发崩溃,建议加入必要的错误检测机制。 --- ### 示例解释 假设给定如下样例输入: ``` 5 3 7 2 ``` 按照以上算法流程依次完成各步操作后得到的结果应当分别为 `2` `5`。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值