Sunday, May 1, 2016

UVA 10391 - Compound Words

#include<bits/stdc++.h>
#define i64 long long
#define mx(a,b,c) max(a,max(b,c))
#define mn(a,b,c) min(a,min(b,c))
#define eef else if
#define ff(i,s,e) for(int i=(s); i<e; i++)
#define ff2(i,s,e) for(int i=(s); i>=e; i--)
#define sf scanf
#define pf printf
#define dbug(x) cout<<"x = "<<x<<endl
#define newl cout<<"\n"
#define putcase cout<<"Case "<<++cse<<":"
using namespace std;
int main()
{
  vector<string>vs;
  map<string,bool>mp;
  string s;
  while(cin>>s){
    vs.push_back(s);
    mp[s]=true;
  }
  ff(i,0,vs.size()){
    ff(j,0,vs[i].size()){
            string s1=vs[i].substr(0,j+1);
            string s2=vs[i].substr(j+1,vs[i].size());
            //cout<<s1<<" "<<s2<<endl;
           if(mp[s1] && mp[s2]){
                cout<<vs[i]<<endl;
                break;
            }
    }
  }
 // dbug(mp["zebra"]);
    return 0;
}

No comments:

Post a Comment