T1-10

#include<bits/stdc++.h>
using namespace std;
const int N=105;
struct book
{
    string isbn;
    string name;
    double price;
}b[N],r[N];
int tot=0;
inline void input()
{
    /*while(cin>>b[tot].isbn>>b[tot].name>>b[tot].price)
    {
        if(b[tot].isbn=="0"&&b[tot].name=="0"&&b[tot].price==0)break;
        tot++;
    }*////T1-3
    cin>>tot;
    for(int i=0;i<tot;++i)
    {
        cin>>b[i].isbn>>b[i].name>>b[i].price;
    }
}
inline void output()
{
    /*cout<<tot<<endl;*////T1
    for(int i=0;i<tot;++i)
    {
        cout<<b[i].isbn<<" "<<b[i].name<<" "<<b[i].price<<endl;
    }
}
inline void bubblesort()
{
    for(int i=0;i<tot;++i)
    {
        for(int j=0;j<tot-i-1;++j)
        {
            if(b[j].price>b[j+1].price)
            {
                book t=b[j];
                b[j]=b[j+1];
                b[j+1]=t;
            }
        }
    }
}
inline void mergesort(int s,int t)//归并排序
{
    if(s==t)return;
    int m=s+(t-s)/2;
    mergesort(s,m);
    mergesort(m+1,t);
    int i=s,j=m+1,k=s;
    while(i<=m&&j<=t)r[k++]=b[i].price<=b[j].price?b[i++]:b[j++];
    while(i<=m)r[k++]=b[i++];
    while(j<=t)r[k++]=b[j++];
    for(int i=s;i<=t;++i)b[i]=r[i];
}
inline void update()
{
    double sum=0;
    for(int i=0;i<tot;++i)sum+=b[i].price;
    sum/=tot;
    cout<<sum<<endl;
    for(int i=0;i<tot;++i)b[i].price*=b[i].price<sum?1.2:1.1;
}
inline void inverse()
{
    for(int i=0;i<tot/2;++i)
    {
        int j=tot-i-1;
        book t=b[j];
        b[j]=b[i];
        b[i]=t;
    }
}
inline void findmax()
{
    double mmax=0;
    int num=0;
    for(int i=0;i<tot;++i)
    {
        if(mmax==b[i].price)num++;
        if(mmax<b[i].price)
        {
            mmax=b[i].price;
            num=1;
        }
    }
    cout<<num<<endl;
    for(int i=0;i<tot;++i)
    {
        if(b[i].price==mmax)
        {
            cout<<b[i].isbn<<" "<<b[i].name<<" "<<b[i].price<<endl;
        }
    }
}
inline void findlove()
{
    int n;
    cin>>n;
    for(int j=0;j<n;++j)
    {
        string name;
        cin>>name;
        int num=0;
        for(int i=0;i<tot;++i)
        {
            if(b[i].name==name)num++;
        }
        if(num==0)
        {
            cout<<"Sorry,there is no your favourite!"<<endl;
        }
        else
        {
            for(int i=0;i<tot;++i)
            {
                if(b[i].name==name)
                {
                    cout<<b[i].isbn<<" "<<b[i].name<<" "<<b[i].price<<endl;
                }
            }
        }
    }
}
inline void query()
{
    int n;
    cin>>n;
    for(int j=0;j<n;++j)
    {
        int t;
        cin>>t;
        if(t<1||t>tot)
        {
            cout<<"Sorry,the book on the best position doesn't exist!"<<endl;
        }
        else
        {
            t--;
            cout<<b[t].isbn<<" "<<b[t].name<<" "<<b[t].price<<endl;
        }
    }
}
inline void insertbook()
{
    int pos;
    cin>>pos;
    string isbn;
    string name;
    double price;
    cin>>isbn>>name>>price;
    if(pos<1||pos>tot+1)
    {
        cout<<"Sorry,the position to be inserted is invalid!"<<endl;
    }
    else
    {
        pos--;
        for(int i=tot;i>=pos;--i)
        {
            b[i]=b[i-1];
        }
        b[pos].isbn=isbn;
        b[pos].name=name;
        b[pos].price=price;
        tot++;
        output();
    }
}
inline void deletebook()
{
    int pos;
    cin>>pos;
    if(pos<1||pos>tot)
    {
        cout<<"Sorry,the position to be deleted is invalid!"<<endl;
    }
    else
    {
        pos--;
        tot--;
        for(int i=pos;i<tot;++i)b[i]=b[i+1];
        output();
    }
}
inline void repeatdelete()
{
    cin>>tot;
    for(int i=0;i<tot;++i)
    {
        cin>>b[i].isbn>>b[i].name>>b[i].price;
        for(int j=0;j<i;++j)
        {
            if(b[i].isbn==b[j].isbn)
            {
                i--;
                tot--;
                break;
            }
        }
    }
    cout<<tot<<endl;
    output();
}
int main()
{
    cout<<fixed<<setprecision(2);
    /*input();*////T1-9
    /*bubblesort();
    mergesort(0,tot-1);*////T2,两种排序都行
    /*update();*////T3
    /*inverse();*////T4
    /*output();*////T1-4
    /*findmax();*////T5
    /*findlove();*////T6
    /*query();*////T7
    /*insertbook();*////T8
    /*deletebook();*////T9
    repeatdelete();
}
View Code

有错欢迎指正

猜你喜欢

转载自www.cnblogs.com/yoududezongzi/p/11536598.html