UVA-10391

题目:https://vjudge.net/problem/UVA-10391

寻找组合单词

直接利用set和string,将每个string拆成两部分,看能否在set中找到对应的部分

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <ctype.h>//isalpha,isdight,toupper
#include <map>
#include <sstream>
typedef long long ll;
using namespace std;
#define inf 0x3f3f3f3f
const int maxn=500000+5;

set<string> s;

int main()
{
    string word;
    while (cin >> word)
    {
        s.insert(word);
    }

    for (set<string>::iterator it = s.begin(); it != s.end(); it++)
    {
        int len = (*it).length();
        for (int i = 1; i < len - 1; i++)
        {
            string head = (*it).substr(0, i);
            string tail = (*it).substr(i, len);
            if (s.count(head) && s.count(tail))
            {
                cout << *it << endl;
                break;
            }
        }
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/abc1235454/article/details/88969915