#include #include #include typedef std::string Word; struct Vector_Word { int size; Word* data; }; typedef std::list Sequence_Word; typedef bool (Predicate) (const Word&); void Filter(const Vector_Word &x, Predicate pi, Sequence_Word &y) { y.clear (); for (int i = 0; i != x.size; ++i) if (pi(x.data[i])) y.push_back (x.data[i]);; } bool Begins_with_G(const Word &word) { return word[0] == 'G'; } #include void Process (std::istream &stream) { Vector_Word x; stream >> x.size; x.data = new Word[x.size]; for (int i = 0; i != x.size; ++i) stream >> x.data[i]; Sequence_Word y; Filter(x, Begins_with_G, y); for (Sequence_Word::const_iterator i = y.begin(); i != y.end(); ++i) std::cout << *i << std::endl; delete[] x.data; } #include void Process (const std::string &filename) { if (filename == "-") { Process (std::cin); } else { std::ifstream stream (filename.c_str ()); if (stream.fail ()) std::cerr << "Opening " << filename << " failed." << std::endl; else Process (stream); } } int main (int argc, char **argv) { if (argc > 1) for (int i = 1; i != argc; ++i) Process (argv[i]); else { std::cout << "Adatbeolvasas modja: " << std::endl << "1 - Szoveges file" << std::endl << "2 - Stdin" << std::endl << std::endl; int v; std::cin >> v; if (v == 1) { std::string filename; std::cout << "Filenev: "; std::cin >> filename; Process (filename); } else if (v == 2) { Process (std::cin); } else { std::cerr << "HIBA! Ervenytelen beviteli mod." << std::endl; exit (-1); } } return 0; }