首页 > 其他 > 详细

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

时间:2014-03-01 04:19:35      阅读:449      评论:0      收藏:0      [点我收藏+]

描述

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;
}


2010华南农业大学校赛-Join a guild,布布扣,bubuko.com

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

原文:http://blog.csdn.net/zhangweiacm/article/details/20140361

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!