UVA_10391: Compound Words

论坛 期权论坛 脚本     
匿名技术用户   2020-12-28 00:01   574   0

分析:读取所有字符串到字符数组中并存在map中建立映射,之后进入主循环,遍历每个字符串,按长度截取成两个字符串,分别在map中查找,如果找到了说明可以拆,进行下一个,不能继续找。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>

using namespace std;
char words[120010][30];
map<string,int> wmap;

int main()
{
 int n=0;
 while(~scanf("%s",words[n]))
 {
  wmap[words[n]]=1;
  n++;
 }

 for(int i=0; i<n; i++)
 {
  int len = strlen(words[i]);
  for(int j=0; j<len; j++)
  {
   char t1[30] = {0};
   char t2[30] = {0};
   strncpy(t1,words[i],j);
   strncpy(t2,words[i]+j,len-j);
   if(wmap[t1] && wmap[t2]){printf("%s\n",words[i]);break;}
  }
 }

    return 0;
}


分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP