If you want to use the STL heavily and don't care if the order of the letters is changed (fantastic becomes acfinst)
Code:#include <string> #include <algorithm> #include <iostream> using namespace std; int main() { string str; cin >> str; // read a word // sort, so unique works sort(str.begin(), str.end()); // now filter multiple letters and output unique_copy(str.begin(), str.end(), ostream_iterator<char>(cout, ""); // note: str is now sorted but still contains multiple letters // if you don't want that, do // unique(str.begin(), str.end()); // which alters str, but doesn't ouput automatically return 0; }




CornedBee
Reply With Quote