#include<iostream>
#include<list>
#include<algorithm>
#include<vector>
using namespace std;
class student
{
public:
string name;
int roll_number;
student(string n,int rn)
{
name=n;
roll_number=rn;
}
};
struct StudentNameIs {
std::string key;
StudentNameIs(const std::string& k) : key(k) {}
bool operator()(const student& s) const { return key == s.name; }
};
void display(list<student> &s)
{
list<student> :: iterator p;
for(p=s.begin();p!=s.end();p++)
cout<<p->name<<" "<<p->roll_number<<endl;
}
int main()
{
student s1("J",63),s2("P",29),s3("M",12),s4("S",71),s5("R",04);
list<student> student_list;
student_list.push_back(s1);
student_list.push_back(s2);
student_list.push_back(s3);
student_list.push_back(s4);
student_list.push_back(s5);
display(student_list);
list<student> :: iterator q;
string temp;
list<student> :: iterator s,e;
s=student_list.begin();
e=student_list.end();
//Accepting name of the student from the user to display roll number of it.
cout<<"Please Enter the name of student:"<<endl;
cin>>temp;
q=find_if(s, e, StudentNameIs(temp));
cout<<"The number is "<<q->roll_number<<endl;
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGxpc3Q+CiNpbmNsdWRlPGFsZ29yaXRobT4KI2luY2x1ZGU8dmVjdG9yPgoKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpjbGFzcyBzdHVkZW50CnsKICAgIHB1YmxpYzoKICAgIHN0cmluZyBuYW1lOwogICAgaW50IHJvbGxfbnVtYmVyOwoKICAgIHN0dWRlbnQoc3RyaW5nIG4saW50IHJuKQogICAgewogICAgICAgIG5hbWU9bjsKICAgICAgICByb2xsX251bWJlcj1ybjsKICAgIH0KfTsKCnN0cnVjdCBTdHVkZW50TmFtZUlzIHsKICAgc3RkOjpzdHJpbmcga2V5OwogICBTdHVkZW50TmFtZUlzKGNvbnN0IHN0ZDo6c3RyaW5nJiBrKSA6IGtleShrKSB7fQogICBib29sIG9wZXJhdG9yKCkoY29uc3Qgc3R1ZGVudCYgcykgY29uc3QgeyByZXR1cm4ga2V5ID09IHMubmFtZTsgfQp9OwoKdm9pZCBkaXNwbGF5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