hdu 1075 What Are You Talking About (字典树·文字翻译)

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1075

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. 
         
大意:给出字典类内容和需要翻译的文章输出翻译后的文字内容。
字典树应用。在字典树上每一个单词结尾字符的节点保存英语单词信息和结束信息,然后就是字符串的处理了。
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
struct node{
    bool cover;
    char word[15];
    node *next[26];
    node(){
        cover=0;
        memset(next,0,sizeof(next));
        memset(word,0,sizeof(word));
    }
};
node *root;
void insert(char *s1,char *s2){
     int length=strlen(s2);
     node *t=root;
     for(int i=0;i<length;i++){
         if(t->next[s2[i]-'a']==0){
              t->next[s2[i]-'a']=new node(); //cool
         }
         t=t->next[s2[i]-'a'];
     }
     t->cover=1;
     strcpy(t->word,s1);
}
void del(node *p){
    if(p==NULL)return ;
    for(int i=0;i<26;i++)del(p->next[i]);
    delete p;
}
char* query(char *s){
    node *t=root;
    int length=strlen(s);
    for(int i=0;i<length;i++){
         if(t->next[s[i]-'a']==0)return s;
         t=t->next[s[i]-'a'];
    }
    if(t->cover)return t->word;  //cover=1的作用:代表是完整的词
    return s;
}
char str[3005],s1[15],s2[15];
int main(){
    //freopen("cin.txt","r",stdin);
    root=new node ();
    cin>>str;
    while(~(scanf("%s",s1))){
        if(strcmp(s1,"END")==0)break;
        scanf("%s",s2);
        insert(s1,s2);
    }
    cin>>str;
    getchar();  //gets 也吸收'\n' 连续使用却不会
    while(gets(str)){
        if(str[0]=='E')break;  //不知道为何我用if(strcmp(str,"END")==0)break; 就不能跳出,输出str是"END"的啊
        char ss[20];
        int length=strlen(str),top=0;
        str[length++]='\n';
        for(int i=0;i<length;i++){
            if(!(str[i]>=97&&str[i]<=122)){
                ss[top]=0;
                if(top>0)printf("%s",query(ss));
                printf("%c",str[i]);
                top=0;
            }
            else {  //小写字母
                ss[top++]=str[i];
            }
        }
    }
    del(root);
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
重磅,最新网络安全等级保护(等保2.0)标准全集 金融行业网络安全等级保护实施指引(2020) 金融行业网络安全等级保护实施指引 第1部分:基础和术语 金融行业网络安全等级保护实施指引 第2部分:基本要求 金融行业网络安全等级保护实施指引 第3部分:岗位能力要求和评价指引 金融行业网络安全等级保护实施指引 第4部分:培训指引 金融行业网络安全等级保护实施指引 第5部分:审计要求 金融行业网络安全等级保护实施指引 第6部分:审计指引 网络安全等级保护测评要求(2019) 网络安全等级保护定级指南(2020) 网络安全等级保护基本要求(2019) 网络安全等级保护实施指南(2019) 网络安全事件应急演练指南(2020) 网络安全等级保护测评过程指南(2018) 网络安全等级保护安全设计技术要求(2019) 网络安全等级保护安全管理中心技术要求(2018) 民用航空网络安全等级保护定级指南(2018) 民用航空网络安全等级保护基本要求(2020) 信息系统安全保障评估框架 第1部分:简介和一般模型(2008) 信息系统安全保障评估框架 第2部分:技术保障(2008) 信息系统安全保障评估框架 第3部分:管理保障(2008) 信息系统安全保障评估框架 第4部分:工程保障(2008) 证券期货业网络安全等级保护测评要求(2021) 证券期货业网络安全等级保护基本要求(2021) 云计算 云服务采购指南(2019) 云计算服务安全指南(2014) 网络安全事件应急预案(2017) 报业网络安全等级保护定级参考指南V2.0(2020) 个人信息安全规范(2020) 广播电视网络安全等级保护定级指南(2020) 计算机信息系统 安全保护等级划分准则(1999)
网络安全等保知识的梳理可以包括以下几个方面: 1. 物理安全:确保网络设备所处的场地和设备本身的安全。包括设备防盗、设备防毁、防止电磁信息泄露、防止线路截获、抗电磁干扰和电源保护等。 2. 技术安全:在控制点上增加网络恶意代码防范、剩余信息保护和抗抵赖等措施。这些措施可以提高网络安全性,防止网络遭受恶意攻击和数据泄露。 3. 管理安全:包括系统备案、安全测评、监控管理和安全管理中心等控制点。通过这些管理措施,可以对网络进行全面的监控和管理,及时发现并应对潜在的安全威胁。 4. 堡垒机:也称为运维安全审计系统,它的核心功能是4A,即身份验证、账号管理、授权控制和安全审计。堡垒机可以有效地管理和控制用户的访问权限,提高系统安全性。 以上是网络安全等保知识的梳理。通过物理安全、技术安全、管理安全和堡垒机等方面的措施,可以提高网络安全性,保护重要数据和系统免受恶意攻击。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [干货-等保三级的三个必备知识(整理精华梳理)](https://download.csdn.net/download/zhou040803/12053564)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [等保知识点总结](https://blog.csdn.net/weixin_44839866/article/details/119941020)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值