Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <iterator>
- #include <algorithm>
- using namespace std;
- struct toy
- {
- int index;
- string name;
- int price;
- int age;
- };
- /* for_each and lambda unwrap to this function:
- void my_for_each(vector<toy> toys, void* lambdaf) {
- for (vector<toy>::iterator a = toys.begin(); a != toys.end(); ++a)
- lambdaf(*a, **hooked_kwargs);
- }
- void lambdaf(toy& a, vecotr<int>& answer, int x, int y) {
- if (a.age >= x && a.age <= y)
- answer.push_back(a.index);
- }
- void final_unwrap(vector<toy> toys, vector<int>& answer, int x, int y) {
- for (vector<toy>::iterator it = toys.begin(); it != toys.end(); ++it) {
- if ((*it).age >= x && (*it).age <= y)
- answer.push_back((*it).index);
- }
- }
- */
- int main(void)
- {
- ifstream in("/Users/masha/Documents/PrAlgo18/PrAlgo18/input");
- //ifstream in("input.txt");
- //ofstream out("output.txt");
- vector<toy> toys;
- int x,y,n;
- in >> n;
- toy t;
- for (int i = 0; i < n; i++)
- {
- in >> t.name >> t.price >> t.age;
- t.index = i + 1;
- toys.push_back(t);
- }
- in >> x >> y;
- vector<int> answer;
- for_each(toys.begin(), toys.end(), [&answer, x, y](toy a) { if (a.age >= x && a.age <= y) answer.push_back(a.index);});
- cout << answer.size() << endl;
- for (int i = 0; i < answer.size(); i++) cout << answer[i] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment