uva 10391 Compound Words 习题5-5 (STL string、set练习)

题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1332


参考博客:http://www.xuebuyuan.com/445444.html 感谢分享

#include<stdio.h>
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
using namespace std;
set<string> a,ans;
int main(){
    string temp;
    while(cin >>temp){
        //if(temp=="0") break;//用于本地测试
        a.insert(temp);
    }

    set<string>::iterator it;
    for(it=a.begin();it!=a.end();it++){
        string s=*it;
        for(int i=0;i<s.length();i++)
        if(a.find(s.substr(0,i))!=a.end()){
            if(a.find(s.substr(i,s.length()))!=a.end())
                ans.insert(s);
        }
    }

    for(set<string>::iterator it=ans.begin();it!=ans.end();it++)
        cout << *it<<endl;
    return 0;
}


说明:find()的用法  、substr()用法



你可能感兴趣的:(uva 10391 Compound Words 习题5-5 (STL string、set练习))