Untitled

mail@pastecode.io avatar
unknown
plain_text
13 days ago
2.7 kB
1
Indexable
Never
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;

struct student
{
    long  id;
    string xm;
    char x;
    string shri;
    string youbian;
    string dizhi;
    string QQ;
    string hao;
};
bool panid(student i, student j)
{
    return i.id > j.id;
}
int main()
{
    int n;
    cin>>n;
    vector<student> stu;
    for(int i=0;i<n;i++)
    {
        student temp;
        cin>>temp.id;
        cin>>temp.xm;
        
        cin>>temp.x;
        cin>>temp.shri;
        cin>>temp.youbian;
        cin>>temp.dizhi;
        cin>>temp.QQ;
        cin>>temp.hao;
        stu.push_back(temp);
    }

    int order;
    cin>>order;
    if(order==1)
    {
        student temp;
        cin>>temp.id;
        cin>>temp.xm;
        cin>>temp.x;
        cin>>temp.shri;
        cin>>temp.youbian;
        cin>>temp.dizhi;
        cin>>temp.QQ;
        cin>>temp.hao;
        stu.push_back(temp);
        sort(stu.begin(),stu.end(),panid);
        cout<<"The records is:"<<endl;
        for(auto i:stu)
        {
            cout << i.id << " " << i.xm<<" "<<i.x<<" "<<i.shri<<" "<<i.youbian<<" "<<i.dizhi<<" "<<i.QQ<<" "<<i.hao<<endl;
        }
    }
    else if(order==2)
    {
        long num;
        cin>>num;
        vector<student>::iterator it=stu.begin();
        for(;it!=stu.end();)
        {
            if(it->id==num)
            {
                stu.erase(it,it+1);
                break;
            }
        }
        sort(stu.begin(),stu.end(),panid);
        cout<<"The records is:"<<endl;
        for(auto i:stu)
        {
             cout << i.id << " " << i.xm<<" "<<i.x<<" "<<i.shri<<" "<<i.youbian<<" "<<i.dizhi<<" "<<i.QQ<<" "<<i.hao<<endl;
        }

    }
    else if(order==3)
    {
        long num;
        cin>>num;
        vector<student>::iterator it=stu.begin();
        for(;it!=stu.end();)
        {
            if(it->id==num)
            {
                break;
            }
        }
        if(it==stu.end())
        {
            cout<<"not found"<<endl;
        }
        else
        {
            auto i = *it;
            {
                cout << i.id << " " << i.xm<<" "<<i.x<<" "<<i.shri<<" "<<i.youbian<<" "<<i.dizhi<<" "<<i.QQ<<" "<<i.hao<<endl;
            }
        }
    }
    else
    {
       sort(stu.begin(),stu.end(),panid);
        cout<<"The records is:"<<endl;
        for(auto i:stu)
        {
            cout << i.id << " " << i.xm<<" "<<i.x<<" "<<i.shri<<" "<<i.youbian<<" "<<i.dizhi<<" "<<i.QQ<<" "<<i.hao<<endl;
        }
    }
    system("pause");
}
Leave a Comment