#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
vector<string> words;
class kmap
{
public:
kmap (const int &v):defVal (v)
{
}
int &getVal(const string &k)
{
if (m.find(k) == m.end())
return defVal;
else
return m[k];
}
int &operator[] (const string &k)
{
return m[k];
}
std::map<string,int> m;
int defVal;
};
kmap ver(-1);
int main()
{
string word, s1, s2;
int i, j;
i=0;
while (cin >> word)
{
words.push_back(word);
ver[word]=i++;
}
int list_len = words.size();
for (i=0 ; i<list_len ; i++)
{
int wlen = words[i].length();
//cout << words[i] << endl;
for (j=1 ; j<wlen ; j++)
{
s1 = words[i].substr(0,j);
s2 = words[i].substr(j,wlen);
//cout << "\t" << ver[s1] << "--" << ver[s2] << endl;
if (ver.getVal(s1)!=-1 && ver.getVal(s2)!=-1 && ver[s1]!=i && ver[s2]!=i)
{
cout << words[i] << endl;
break;
}
}
}
return 0;
}
Thursday, November 10, 2011
[UVa] 10391 - Compound Words
Subscribe to:
Post Comments (Atom)
Connect Rapoo MT750S with Linux (Tested on Manjaro)
I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...
-
I like coding a lot, keeps me glued to the PC for hours. For that reason it's a need to edit the Syntax Highlighter to suit my eyes for...
-
I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...
-
Method: The problem at first glance seems too straightforward but it's not that much. Think a bit about the lines "Erin can add ...
No comments:
Post a Comment
Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.