Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <algorithm>
- #include <string>
- #include <vector>
- #include <functional>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- struct Person
- {
- string name;
- string secondname;
- string surname;
- string number;
- };
- class compare: public unary_function<Person &, void>
- {
- private:
- string tmp;
- string temp;
- public:
- compare(string a, string b): tmp(a), temp(b)
- {
- }
- void operator()(Person &x)
- {
- if(x.number.substr(0, 2) == tmp)
- x.number.replace(0, 2, temp);
- }
- };
- void print(Person &x)
- {
- out << x.name << " " << x.secondname << " " << x.surname << " " << x.number << endl;
- }
- int main()
- {
- vector <Person> vec;
- Person List;
- int n;
- in >> n;
- for(int i = 0; i < n; i++)
- {
- in >> List.name;
- in >> List.secondname;
- in >> List.surname;
- in >> List.number;
- vec.push_back(List);
- }
- string tmp, temp;
- in >> tmp;
- in >> temp;
- in.close();
- compare comp(tmp, temp);
- for_each(vec.begin(), vec.end(),comp);
- out << n << endl;
- for_each(vec.begin(), vec.end(), print);
- out.close();
- return 0;
- }
- //2
- #include <fstream>
- #include <algorithm>
- #include <string>
- #include <vector>
- #include <functional>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- struct Person
- {
- string name;
- string secondname;
- string surname;
- string number;
- };
- void print(Person &x)
- {
- out << x.name << " " << x.secondname << " " << x.surname << " " << x.number << endl;
- }
- int main()
- {
- vector <Person> vec;
- Person List;
- int n;
- in >> n;
- for (int i = 0; i < n; i++)
- {
- in >> List.name;
- in >> List.secondname;
- in >> List.surname;
- in >> List.number;
- vec.push_back(List);
- }
- string tmp, temp;
- in >> tmp;
- in >> temp;
- in.close();
- for_each(vec.begin(), vec.end(), [tmp, temp](Person &x){if (x.number.substr(0, 2) == tmp)
- x.number.replace(0, 2, temp);});
- out << n << endl;
- for_each(vec.begin(), vec.end(), print);
- out.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement