MY name is ruhul amin

ISLAMIC UNIVERSITY OF KUSHTIA

Thursday, April 25, 2013

c++program using vector

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
class name
{
 public:
 char a;
 int b;
};
bool com(const name g,const name t)
{
    if(g.a==t.a)
    if(g.b<t.b)
    return 1;
    else
    return 1;
}
int main()
{
    int n;
    char a;
    int b;
    name ob;
    while(cin>>n)
    {
        vector<name>v;
        for(int i=0;i<n;i++)
        {
            cin>>a>>b;
            ob={a,b};
            v.push_back(ob);
        }
        vector<name>s(v);
        sort(s.begin(),s.end(),com);
        for(int i=0;i<s.size();i++)
        cout<<s[i].a<<" "<<s[i].b<<endl;
    }
    return 0;
}

No comments:

Post a Comment