C++ simple dictionary: list of sorted words -
int main() { vector<string> words; cout << "please enter words\n"; (string temp; cin >> temp; words.push_back(temp), sort(words.begin(), words.end())) (int = 0; < words.size(); ++i){ if (i == 0 || words[i - 1] != words[i]) cout << words[i] << "\n"; } return 0; } the code must able list of sorted words first letter, example input:
a man plan canal panama; and write:
canal man panama plan could gives me advice mistake in loop. use vs 2013. appreciated. thank's in advance.
#include <iostream> #include <string> #include <algorithm> #include <iterator> #include <set> using namespace std; int main() { multiset<string> words; for(string temp; cin >> temp; words.insert(temp)) { } cout << endl; copy(words.begin(), words.end(), ostream_iterator<string>(cout, "\n")); return 0; }
Comments
Post a Comment