uva 540

本来想开个二维数组,担心数据坑人越界,就用指针写了,开了个指针数组来存放每个队的末尾元素的指针。

#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
struct node{
    node *next;
    int n;
};
int belong[1000005];
node *team[1005];
node *head,*tail;
void add(){
    int m; cin>>m;
    int t=belong[m];
    node *p=new node; p->n=m;
    if(team[t]==NULL){
        if(head==NULL) head=p;
        else tail->next=p;
        p->next=NULL; tail=p;
    }
    else{
        p->next=team[t]->next;
        team[t]->next=p;
        if(team[t]==tail) tail=p;
    }
    team[t]=p;
}
void prt(){
    cout<<head->n<<endl;
    node *p=head;
    int t=belong[head->n];
    if( head==team[t] ) team[t]=NULL;
    head=head->next; delete p;
}
int main()
{
    int c=1,t;
    while(cin>>t){
        if(t==0) break;
        printf("Scenario #%d\n",c++);
        memset(team,0,sizeof(team)); head=tail=NULL;
        while(t--){
            int k,a; cin>>k;
            while(k--){ cin>>a; belong[a]=t; }
        }
        char s[20];
        while(1){
            cin>>s; if(s[0]=='S') { cout<<endl; break; }
            if(s[0]=='E') add();
            else prt();
        }
    }
    return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值