Compound Words UVA - 10391(字符串搜索)

Problem
You are to find all the two-word compound words in a dictionary. A two-word compound word is a word in the dictionary that is the concatenation of exactly two other words in the dictionary.
Solve
1.提高效率我们用 set 输入结束再一并处理
2.迭代处理,符合以下条件就输出
3.每个单词以所有可能分成两部分,分别匹配单词集,均存在即符合条件
Method

string.assign(string, (int)start, (int)length) 分配函数

int main() {//int T; cin >> T; getchar();
    ios::sync_with_stdio(false);
    set<string> ste;
    string s, t;
    while(cin >> s) ste.insert(s);
    for(set<string>::iterator it = ste.begin(); it != ste.end(); it++) {
        s = *it;
        for(int i = 1; i < s.length(); i++) {
            t.assign(s, 0, i);
            if(ste.count(t)) {
                t.assign(s, i, s.length()-i);
                if(ste.count(t))
                    {cout << s << endl; break;}
            }
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值