|
ACCU2007
|
|
recent changes |
Hubert told about the BigFour on the equation of productivity
He also set out some programming challenges:
struct anaIter:public std::iterator<std::forward_iterator_tag,std::string>{
std::string word;
std::string anagram;
anaIter(std::string w=std::string()):word(w){}
std::string operator*(){
if(anagram.size()!=word.size())anagram=word; // special first access
return anagram;
}
anaIter& operator++() {
std::next_permutation(anagram.begin(),anagram.end()); return *this;
}
bool operator==(anaIter const &other)const{
if (other.word.size())return anagram == other.anagram;
else return anagram == word;
}
bool operator!=(anaIter const &other)const{ return !(*this == other);}
};
int main(){
std::string word;
std::cin >> word;
std::copy(anaIter(word), anaIter(),
std::ostream_iterator<std::string>(std::cout,", "));
}
| Last edited April 11, 2007 |
|
recent changes |