UVa10391

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=15&problem=1332&mosmsg=Submission+received+with+ID+11760306

思路很简单,写博客目的是记住find、substr的用法

 

#include<iostream>

#include<set>

using namespace std;



int main()

{

    set<string> s;

    string temp;

    while (cin >> temp)

    {

        s.insert(temp);

    }

    for (set<string>::iterator it = s.begin(); it != s.end(); it++)

    {

        string a = *it;

        for (int i = 1; i < a.length(); ++i)

        {

            if (s.find(a.substr(0, i)) != s.end() && s.find(a.substr(i, a.length() - i)) != s.end())//核心

            {

                cout << a << endl;

                break;

            }

        }

    }

}


 

 

你可能感兴趣的:(uva)