What Are You Talking About

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.


题目意思:给你一本火星字典,然后根据火星字典,把一句话翻译成英文,如果一个词在火星字典里找不
          到就不翻译,直接写出来。
解题思路:通过字典树,将字典进行建树,然后查找,这个题的关键在于怎么把这段发翻译过来,于是想
          到通过函数或者ASCII码判断是否为小写字母,判断到不是时,就将前面的字母输入到树中进行
          查找,若找到就翻译,反之不翻译。这里找不到的判定标准有两个:1.遇到指针为空 2.指针不
          为空但最后一个字母不是树中标记过的字母,比如树中存在asdf,而你输入的为asd,那么就是
          找不到。


#include<iostream>
#include<cstring>
#include<algorithm>
#include<ctype.h>

using namespace std;

char s[3100];
char s2[20];
char s1[20];

struct trie{
	char v[15];  
	int mark;
	trie *next[26];
	trie(){
		mark=0;
		for(int i=0;i<26;i++)
		{
			next[i]=NULL;
		}
	}
}; 

trie *root;

void creat(trie *root,char *str,char *str1)
{
    int len=strlen(str);
	trie *p=root,*q;
	for(int i=0;i<len;i++)
	{
		int sign=str[i]-'a';
		if(p->next[sign]==NULL)
		{
			q=new trie();
			p->next[sign]=q;
			p=p->next[sign];
		}
		else
		{
			p=p->next[sign];			
		}
	}
	p->mark=-1;
	strcpy(p->v,str1);
}

bool find(trie *root,char *str,int m,int j)
{
	trie *p=root;
	int i=m;
	for(i;i<j;i++)
	{
			int id=str[i]-'a';
			p=p->next[id];
			if(p==NULL)
			{
				return false;
			}		
	}
	if(p->mark!=-1)
	    return false;
	cout<<p->v;
	return true;
}

void del(trie *root)
{
	for(int i=0;i<26;i++)
	{
		if(root->next[i])
		{
			del(root->next[i]); 
		}
	}
	delete(root);
}

int main()
{
	char str[10];
	root=new trie();
	scanf("%s",str);
	while(scanf("%s",s1)&&strcmp(s1,"END"))
	{
		scanf("%s",s2);
		creat(root,s2,s1);
	}
	scanf("%s",str);
	gets(s);
	while(gets(s)&&strcmp(s,"END")!=0)
	{
		int len=strlen(s);	
		int num=0;
		for(int a=0;a<len;a++)
		{
			if(s[a]>='a'&&s[a]<='z')
			{
				num++;
			}
			else
			{
				if(s[a-1]<'a'||s[a-1]>'z')
				{
					cout<<s[a];
					num=0;
				}
				else
				{
				    if(!find(root,s,a-num,a))
				    {
				    	for(int q=a-num;q<a;q++)
				    	{
				    		cout<<s[q];
						}
					}
				    cout<<s[a];
				    num=0;
				}
			}
		}
		if(!find(root,s,len-num,len))
	    {
	    	for(int q=len-num;q<len;q++)
			{
		    	cout<<s[q];
			}
		}
		cout<<endl;
	}	
	return 0;
}





can you explain this in chinese as much as you can:Hello everyone. Today I'm going to give you all example of data, so remember we're talking about data understanding. When you have a dataset, what do we do? You want to be able to describe the dataset and analyze the dataset so you understand what data you're working with. I'm going to use one example, so this is about air quality sensing. We work on a project. This is base is just for mobile air quality sensing. The motivation is that while there are actually air quality monitoring stations in most areas, but those are limited. For example, you usually get a dozen in a urban area. It's very limited, so if you consider individually, we go to different places, we go to different rooms. I care more about my neighboring area, so what air quality I'm subject or air pollution I'm subject to. In this particular project, so what we did was that well developed sensing device, and that actually then would be coupled with your mobile phone so that we can collect various air pollutant information gets used, send it to the mobile phone, and then send to the Cloud server so you can do further analysis. So from the data side. We say this is the air quality data , air quality sensing. That's the dataset, it's air quality sensing data. But what are the things I can describe? If you're say, if I'm attending your like, I have this dataset. Will it be the immediate questions you want to ask? Starting point, of course, is that well depending, not in particular order, of course, winds that the size. But there are different ways to ask about it. Size is about okay. How many sensors by per device, also how many users, and also how long? So that was the duration of the study. Also you can get your bit area. To answer this particular question, so for example, like we have, I think on every device you will have sensors for CO, CO2, the max, and then ozone, and also we have temperature, humidity, and those other. You want to be able to specify the specific types of sensors, and then users, since those devices are mobile devices, they're being carried by users. In our study, we had, was 20-30 different users, so they're carrying those devices. We did that over about a half year, so actually have data coming from those users, from those sensing devices for that time duration. We also did some event specific like monitoring is there are certain events happening in certain areas, so we actually did a few more narrowed foot crossed data collection there. The area of course they'll say, Are you talking about say I'm in Boulder. We actually did that and mostly in Boulder but also had a couple of students take the devices. They were riding the bus ride to Denver and also to the airport, and also to a shopping mall. That's basically just understanding about what data being collected, and you can also ask a little bit more about how the data were collected. That's generally the size or the scale. Now of course, when you get to the specifics, will say what your data understanding, is that, what's the norm, what's the potential distribution, the dispersion, and also any extreme values, so this really gets to some of those statistical part. Your statistics you can do basically can look at each with individual readings. You can say that if I take all the CO2 readings, I can then have some way of calculating the average, the mean value, the standard deviation. I can plot the overall distribution and I can actually even show you whether what the normal ranges are here they look okay and they are generally below the threshold, based on the Environmental Protection Agency, or you actually see some extremely high values. That's with CO2. We are concerned if we are above the safety threshold. You're also looking at higher values that are extreme, so those can of course easily plotted. We'll talk about a few visualization capabilities, so that would allow you to plot. You can use a single-line box plot is actually very helpful in this case, where you can quickly show the distribution. Also, it's actually very harmful you want to compare. For example, I have different users or different locations, or different time periods. That actually would allow you to break apart your data and then be able to compare the statistics across different dimensions. That's what kind of data I have or what kind of statistics I can leverage. Then we covered rise of visualization. I'll put it in there. Think about how we can visualize your data, so you can allow you to have some good insights. Some further analysis, you can then plot it, visualization of satellite. You can do individual distribution or you can do some spatial temporal plotting in some comparative study. That's actually all very useful. I want to touch a little bit about also is part of the similarity part, or distance because that's important. As we have said in the class, when you have different objects, those objects are defined by those attributes. Then you want to have some way of identifying similarity or distance similarity. In this case where I will have the air quality sensor readings, so one natural question when you're talking about the similarities that, does it look similar or there's significant differences? Since I have multiple sensors, well, I remember we're talking about the different attributed types and then the different, like whether you have binary values or whether you have other information you can leverage. If you look at my sensors, so if I say my CO, CO_2, the NO_*, and then like ozone, and then you may have PM_2.5. As you can see, these are all numerical values, so you have this time series of those numerical values. But on top of that, you could have, say maybe different location. Then the other way I will also talk about temperature or humidity. I will say actually we also add not just the location, there's also more like the activity. This is actually related to your life. For example, if I'm riding a bus, like biking, riding bus, or I'm out running outdoors, or I'm just sleeping. As we can see, the different types of information, so we're talking about the similarity, I can see the numerical values you have some way with defining the closeness. Or in essence we care more about when they're above a certain threshold, you can quantify this into not just the actual value, can just maybe say 10% or higher above the threshold, 20% or higher, or how often, you can actually convert that into some kind of frequency. Then if you have the different activity, then you've actually grouped that by, remember we're talking about if it's a binary, the binary code encoding, could it be what category of value it can convert data into some binary just okay, you have to match exactly because I only care about the same type of activity because like riding bus is public and would be very different versus when sleeping. Those are all the information you need to consider as you're trying to decide on your similarity function or distance or calculations. Another important thing we talk about is that, remember we're saying like the weighted. The way to the decent calculation, that is actually very important angle because you want to make sure that as you're putting all this together, those attributes are not equal. You want to be able to tailor your similarity calculation or the decent calculation by identifying like say air pollutants data have more severe negative impact when they are above certain threshold. As you can see, even though they are a standard, distance of calculation or similarity calculation functions, you want to be able to understand your problem setting, understand the semantics of your data. Then I have a specific calculation, similarity function that is meaningful for your dataset and for your application scenario. Of course this is just one example, but hopefully that give you an idea about if you are being presented with a particular dataset, what kind of question do you ask or what are the specific things you can do in terms of analyzing data, understanding the potential like semantics, the challenges or issues, or knowledge you can learn on top of it. A particular, the similarity part we'll talk about is that because it's hard to give like say, just use this function and you'll be fine. Many times you need to do the reasoning is about, okay, what do I have? What [inaudible] do I have and what do I care about from my application? I have my calculations, that's more applicable format intended usage of scenarios. That's all. Thank you.
05-24
from nltk.chat.util import Chat # 修改反射字典:使用标准英语替换网络用语 reflections = { "am": "are", # 原"r"改为"are" "was": "were", "i": "you", # 原"u"改为"you" "i'd": "you'd", "i've": "you've", "ive": "you've", "i'll": "you'll", "my": "your", # 原"ur"改为"your" "are": "am", "you're": "I'm", "you've": "I've", "you'll": "I'll", "your": "my", "yours": "mine", "you": "me", "me": "you", # 删除非标准缩写:ur, urs, u } # 重写对话模板:移除网络用语和夸张表达 pairs = ( ( r"I\'m (.*)", ( "You're %1? That's interesting. Tell me more.", # 移除"kekekeke"和表情 "You're %1? That sounds nice.", # 简化表达 ), ), ( r"(.*) don\'t you (.*)", ( "Why do you think I can't %2?", # 改为完整疑问句 "What makes you say I can't %2?", "I probably could if I wanted to, don't you think?" ), ), (r"ye[as] [iI] (.*)", ("You %1? How did that happen?", "Why did you %1?", "I %1 too.")), ( r"do (you|u) (.*)\??", ("Do I %2? Sometimes, depending on the situation.", "I'm not sure. Do you %2?"), ), ( r"(.*)\?", ( "I'm curious why you asked that.", # 移除负面词汇"boring" "That's an interesting question.", ), ), ( r"(cos|because) (.*)", ("I see, that makes sense.", "That's a good reason.", "I understand."), ), ( r"why can\'t [iI] (.*)", ( "I'm not sure why you can't %1.", "Have you tried different approaches?", "When I can't do something, I usually practice more." ), ), ( r"I can\'t (.*)", ( "Why do you think you can't %1?", "That's okay, we all have limitations.", "Maybe with practice you could do it." ), ), ( r"(.*) (like|love|watch) anime", ( "I enjoy anime too. Do you have a favorite series?", # 移除夸张表达 "Anime is an interesting art form.", "What do you like most about anime?" ), ), ( r"I (like|love|watch|play) (.*)", ("That's nice. %2 can be enjoyable.", "Do you have other interests too?"), ), ( r"anime sucks|(.*) (hate|detest) anime", ( "Everyone has different tastes in entertainment.", "What kind of shows do you prefer instead?", ), ), ( r"(are|r) (you|u) (.*)", ("Why do you ask if I'm %3?", "What makes you wonder about that?"), ), ( r"what (.*)", ("I'm not sure about that.", "Could you tell me more about your question?"), ), (r"how (.*)", ("I'd prefer to talk about something else.",)), (r"(hi|hello|hey) (.*)", ("Hello! How are you today?",)), ( r"quit", ( "Goodbye! It was nice talking with you.", # 移除戏剧化表达 "Take care. Hope we can chat again sometime.", ), ), ( r"(.*)", ( "Could you tell me more about that?", "What are your thoughts on this topic?", "Do you enjoy any particular hobbies?", "I'm interested in your perspective." ), ), ) iesha_chatbot = Chat(pairs, reflections) def iesha_chat(): print("Iesha the Normal Chatbot\n---------") # 修改标题 print("Talk to the program by typing in plain English.") print('Enter "quit" when done.') print("=" * 72) print("Hello! I'm Iesha. What's your name?") # 标准化问候语 iesha_chatbot.converse() # 其余代码保持不变... 把她的对话模板变得更复杂
最新发布
09-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值