2010华南农业大学校赛-Join a guild

描述

Almost every MMORPG(Massively Multiplayer Online Role-Playing Game) has a guild(公会) system. Every player can join one guild, and every guild can contain many players. Now you are designing a guild request system. Assume letter is player. Number is guild. Give you some joining event and request about a player or a guild. Your system tells me which guild the player belongs to or lists the guild’s member.

输入

The first line of the input is an integer n (1<=n<=5000), means the total operation.

There are only two kind of operation which format like “J p g” and “R q.

(0<=p<=9), (a<=g<=z)

输出

The operation begins with “J” means the play “p” join the guild “g”. This operation has no output.

The operation begins with “R” means the request arguments is “q”.

If “q” is an integer, your system should list the guild-q”‘s member in lexicographic order. If nobody in guild-q” then output “empty”.

If “q” is a letter, your system should output the guild id which the player-q belongs to.

If the player didn’t join any guild, output “solo”.

样例输入

15
J a 1
R c
R 2
J a 2
J b 2
R a
R b
R 1
R 2
J c 3
J b 3
J c 3
R b
R 3
R 2

样例输出

solo
empty
2
2
empty
ab
3
bc
a


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
    char str[5000];
    int i;
}q[100];
int cmp(const void *a,const void *b)
{
    return strcmp((*(node*)a).str,(*(node*)b).str);
}
int fun(char x)
{
    x=x-'0';
    if(q[x].i==0){cout<<"empty"<<endl;return 0;}
    //qsort(q,q[x].i,sizeof(q[x]),cmp);
    for(int i=0;i<q[x].i;i++)
        for(int j=i;j<q[x].i;j++)
           if(q[x].str[i]>q[x].str[j])
             {
                    char t;
                    t=q[x].str[i];
                    q[x].str[i]=q[x].str[j];
                    q[x].str[j]=t;
             }
    for(int i=0;i<q[x].i;i++)
        cout<<q[x].str[i];
    cout<<endl;

}
int fun1(char x)
{
   for(int i=0;i<10;i++)
   {
       if(q[i].i==0)continue;
       for(int j=0;j<=q[i].i;j++)
          if(int(q[i].str[j])==int(x))return i;
   }
   return -1;
}
void cz(char x)
{
  for(int i=0;i<10;i++)
   {
       if(q[i].i==0)continue;
       for(int j=0;j<=q[i].i;j++)
          if(int(q[i].str[j])==int(x))
          {
              while(j<=q[i].i-1)
                {
                    q[i].str[j]=q[i].str[j+1];
                     j++;
                }
              q[i].i--;
              break;
          }
   }
}
int main()
{
    int n,y;
    char m,x;
    while(cin>>n)
    {
        memset(q,0,sizeof(q));
        for(int i=0;i<n;i++)
        {
            cin>>m;
            if(m=='J')
            {
                cin>>x>>y;
                cz(x);
                q[y].str[q[y].i++]=x;

            }
            if(m=='R')
            {
                cin>>x;
                if(x>='0'&&x<='9')
                {
                    fun(x);
                }
                else
                {   int z=fun1(x);
                   if(z>=0)
                   cout<<z<<endl;
                   else cout<<"solo"<<endl;
                }
            }
        }
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值