#include <vector> #include <algorithm> #include <functional> #include <iostream> using namespace std; namespace exam { vector<char> vc; void print() {copy(vc.begin(),vc.end(),ostream_iterator<char>(cout));} void rprint() {copy(vc.rbegin(),vc.rend(),ostream_iterator<char>(cout));} void push(char c) {vc.insert(find_if(vc.begin(),vc.end(), bind2nd(greater<char>(),c)),c);} } int main(int argc,char** argv) { exam::push('c'); exam::push('a'); exam::push('t'); exam::push('x'); exam::push('i'); exam::push('s'); exam::print(); cout << endl; exam::rprint(); cout << endl; } |
#include <string> #include <vector> #include <algorithm> #include <functional> #include <iostream> using namespace std; #pragma warning(disable : 4786) int main(int argc,char** argv) { vector<string> vs; string s; while (cin >> s) vs.push_back(s); sort(vs.begin(),vs.end()); copy(vs.begin(),vs.end(),ostream_iterator<string>(cout," ")); cout << endl; } |
#include <string> #include <vector> #include <algorithm> #include <functional> #include <iostream> using namespace std; #pragma warning(disable : 4786) typedef vector<string>::iterator vsiter; bool InitLess(const string& s,const string& t) {return s[0] < t[0];} int main(int argc,char** argv) { vector<string> vs; string s; while (cin >> s) vs.push_back(s); sort(vs.begin(),vs.end()); pair<vsiter,vsiter> it = equal_range(vs.begin(),vs.end(),"a",InitLess); copy(it.first,it.second,ostream_iterator<string>(cout," ")); cout << endl; } |
vs.erase(it.first,it.second); copy(vs.begin(),vs.end(),ostream_iterator<string>(cout," ")); cout << endl; |
#include <string> #include <vector> #include <set> #include <algorithm> #include <functional> #include <iostream> using namespace std; #pragma warning(disable : 4786) bool IsKankitu(const string& s) { static set<string> tbl; bool bFirst = true; if (bFirst) { bFirst = false; tbl.insert("lemon"); tbl.insert("orange"); } return tbl.find(s) != tbl.end(); } int main(int argc,char** argv) { vector<string> vs; string s; while (cin >> s) vs.push_back(s); vs.erase(remove_if(vs.begin(),vs.end(),IsKankitu),vs.end()); copy(vs.begin(),vs.end(),ostream_iterator<string>(cout," ")); cout << endl; } |