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
You are to find all the hat’s words in a dictionary.
Input
Only one case.
Output
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;
}
本文深入探讨了AI音视频处理领域中的关键技术,特别是视频分割与语义识别,详细解释了如何利用这些技术实现更智能、更高效的音视频处理流程。通过实际案例分析,展示了在不同场景下应用这些技术所能带来的显著效果。
1041

被折叠的 条评论
为什么被折叠?



