C ++ 객체 지향 프로그래밍 040 : 목록 ---- (Peking University Mooc)

기사 디렉토리


특별 블로그 링크

Peking University C ++ POJ 수업 후 연습 블로그 전체 솔루션 기록


원제

여기에 사진 설명 삽입

여기에 사진 설명 삽입


암호

#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
typedef list<int> L;

void printlist(const list<int>::iterator stri,const list<int>::iterator endi)
{
    
    
    list<int>::iterator tmp;
    for(tmp = stri;tmp!=endi;tmp++)
        cout<<*tmp<<' ';
    cout<<endl;
    return;
}

int main()
{
    
    
    L lst[10010];
    L::iterator i;
    string func;
    int opernumbers,number,target,name;
    cin>>opernumbers;
    while(opernumbers--)
    {
    
    
        cin>>func;
        if(func == "new")
            cin>>name;
        else if(func == "add")
        {
    
    
            cin>>name>>number;
            lst[name].push_back(number);
        }
        else if(func == "merge")
        {
    
    
            cin>>name>>target;
            lst[name].merge(lst[target]);
        }
        else if(func == "unique")
        {
    
    
            cin>>name;
            lst[name].sort();
            lst[name].unique();
        }
        else
        {
    
    
            cin>>name;
            lst[name].sort();
            printlist(lst[name].begin(),lst[name].end());
        }
    }
    return 0;
}

추천

출처blog.csdn.net/qq_37500516/article/details/115034765