HDOJ Hat’s Words

本文深入探讨了AI音视频处理领域中的关键技术,特别是视频分割与语义识别,详细解释了如何利用这些技术实现更智能、更高效的音视频处理流程。通过实际案例分析,展示了在不同场景下应用这些技术所能带来的显著效果。
 

Hat’s Words

http://acm.hdu.edu.cn/diy/contest_showproblem.php?cid=12654&pid=1002

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 4   Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size: ← →

Problem Description

A hat’s word is a word in the dictionary that is the concatenation of exactly two other words in the dictionary.
You are to find all the hat’s words in a dictionary.

Input

Standard input consists of a number of lowercase words, one per line, in alphabetical order. There will be no more than 50,000 words.
Only one case.

Output

Your output should contain all the hat’s words, one per line, in alphabetical order.

Sample Input

a
ahat
hat
hatword
hziee
word

Sample Output

ahat
hatword

Author

戴帽子的
 
把一个单词分成前后两部分进行查找,注意在拷贝前部分的时候记得要加串结束符。

#include<iostream>
#include<cstring>
using namespace std;
struct trie{
       struct trie *child[26];
       int flag;  //用来判断这个点是不是一个单词的最后一个点
};
struct trie *root;
char save[50000][100];//保存字符串
void insert(char *source){
     int len,i,j;
     len=strlen(source);
     if(len==0)  return ;
     struct trie *current ,*newnode;
     current=root;
     for(i=0;i<len;i++){
          if(current->child[source[i]-'a']!=NULL)
              current=current->child[source[i]-'a'];
          else{
              newnode=new trie;
              for(j=0;j<26;j++)
                  newnode->child[j]=NULL;
              current->child[source[i]-'a']=newnode;
              current=newnode;    
          }                                            
     }   
    current->flag=1;  //单词的最后一个点   
}
int find(char *source){
    int i,len;
    len=strlen(source);
    if(len==0)  return 0;
    struct trie *current;
    current=root;
    for(i=0;i<len;i++){
        if(current->child[source[i]-'a']!=NULL)
            current=current->child[source[i]-'a'];
        else
           return 0;                                        
    }
    if(current->flag==1)  //是一个完整的单词就返回1
         return 1;
    else
         return 0;       
}
int main(){
    int i,j,cnt=0;
    char c1[100],c2[100],temp[100];
    root=new trie;
    for(i=0;i<26;i++)
       root->child[i]=NULL;
    while(scanf("%s", temp)!=EOF){
        insert(temp);
        strcpy(save[cnt++],temp);                 
    }
    for(i=0;i<cnt;i++){                    
        for(j=1;j<strlen(save[i]);j++){
            strncpy(c1,save[i],j);
            strcpy(c2,save[i]+j);
            c1[j]='\0';  //不要漏了这里
            if(find(c1) && find(c2) ){
                puts(save[i]);
                break;
            }                                                                   
        } 
    }
      //   system("pause");
    return 0;
}

 

 用stl搞定

#include<iostream>
#include<string>
#include<map> 
using namespace std;
int main(){
    map<string ,int > m;
  //  map<string ,int >::iterator It;
    string str[50005];
    int cnt=0;
    while(cin>>str[cnt])
         m[str[cnt++]]=1;   
   for(int i=0;i<cnt;i++){
           for(int j=1;j<str[i].size();j++){
              string s1(str[i],0,j);
              string s2(str[i],j);
              if(m[s1]==1 && m[s2]==1){
                   cout<<str[i]<<endl;
                   break;
               }
            }  
                                   
   }
//system("pause");
return 0;
}



 

 

 

 

 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值