算法竞赛入门经典(第2版)习题5-5 复合词 UVa10391

来源:互联网 发布:网络集成平台 编辑:程序博客网 时间:2024/06/05 17:00

用拆分词的思路很棒

#include <iostream>  #include <cstdio>  #include <cstdlib>  #include <string>  #include <map>  #define INF 1E9  using namespace std;  map<string,bool> hash;  string s[150000];  int main()  {      int i,j;      int cnt=0;      hash.clear();      while(cin>>s[cnt])      {          hash[s[cnt]]=1;          cnt++;      }      string a,b;      for(i=0;i<cnt;i++)       for(j=0;j<s[i].size()-1;j++)       {          a=s[i].substr(0,j+1);          if(!hash[a])continue;          b=s[i].substr(j+1);          if(!hash[b])continue;          cout<<s[i]<<endl;          break;       }       return 0;  }  
阅读全文
0 0
原创粉丝点击