hdu 5071 chat

一个模拟QQ的题。


共有八种操作,都比较好实现。


关键的核心是:


最后一句话。


CLJ will say goodbye to every active window he has ever spoken to at last, “active” here means the window has not been closed so far. The logging format is “Bye u: c” where u is the priority and c is the number of words he has ever spoken to this window. He will always say good bye to the current top girl if he has spoken to her before he closes it.
 

自己读得是 当执行关闭操作的时候如果是top并且说过话要 say goodbye!原来正确的题意是在最后按顺序输出说过话的girl ,并且top状态的为第一个。囧~~~~

因为这个wa了好多次。。。。


代码:

#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
string s;
string ss[10]= {"Add","Close","Chat","Rotate","Prior","Choose","Top","Untop"};
int flag,top,u;
struct node
{
    int num;
    int res;
} p[5002];
queue<node> q1,q2;
void clear2()
{
    while(!q2.empty())
    {
        q2.pop();
    }
}
void jiaohuan()
{
    node a;
    while(!q2.empty())
    {
        a=q2.front();
        q2.pop();
        q1.push(a);
    }
}
void o1()
{
    clear2();
    node a;
    while(!q1.empty())
    {
        a=q1.front();
        q1.pop();
        if(a.num==u)
            flag=1;
        q2.push(a);
    }
    a.num=u,a.res=0;
    if(!flag)
    {
        q2.push(a);
        printf("success.\n");
    }
    else
        printf("same priority.\n");
    jiaohuan();
}
void o2()
{
    clear2();
    node a;
    int ans;
    int sum=0;
    while(!q1.empty())
    {
        a=q1.front();
        q1.pop();
        if(!flag)
            sum++;
        if(a.num==u)
        {
            flag=1;
            ans=a.res;
            continue;
        }
        q2.push(a);
    }
    if(flag)
        printf("close %d with %d.\n",u,ans);
    else
        printf("invalid priority.\n");

    jiaohuan();
}
void o3()
{
    clear2();
    node a;
    int sum=0;
    if(q1.empty())
    {
        printf("empty.\n");
        return ;
    }
    while(!q1.empty())
    {
        a=q1.front();
        q1.pop();
        sum++;
        if(sum==1&&top==-1)
        {
            a.res+=u;
            printf("success.\n");
        }
        if(top==a.num)
        {
            a.res+=u;
            printf("success.\n");
        }
        q2.push(a);
    }
    jiaohuan();
}
void o4()
{
    clear2();
    node a,b;
    int ans=0;
    while(!q1.empty())
    {
        a=q1.front();
        q1.pop();
        ans++;
        if(ans==u)
        {
            b=a;
            flag=1;
            continue;
        }
        q2.push(a);
    }
    if(flag)
    {
        q1.push(b);
        printf("success.\n");
    }
    else
        printf("out of range.\n");
    jiaohuan();
}
void o5()
{
    if(q1.empty())
    {
        printf("empty.\n");
        return ;
    }
    clear2();
    node a,b;
    b.num=0;
    while(!q1.empty())
    {
        a=q1.front();
        q1.pop();
        if(a.num>b.num)
            b=a;
        q2.push(a);
    }
    q1.push(b);
    while(!q2.empty())
    {
        a=q2.front();
        q2.pop();
        if(a.num!=b.num)
            q1.push(a);
    }
    printf("success.\n");
}
void o6()
{
    clear2();
    node a,b;
    while(!q1.empty())
    {
        a=q1.front();
        q1.pop();
        if(a.num==u)
        {
            b=a;
            flag=1;
            continue;
        }
        q2.push(a);
    }
    if(flag)
    {
        q1.push(b);
        printf("success.\n");
    }
    else
        printf("invalid priority.\n");
    jiaohuan();
}
void o7()
{
    clear2();
    node a;
    while(!q1.empty())
    {
        a=q1.front();
        q1.pop();
        if(a.num==u)
        {
            flag=1;
            top=a.num;
        }
        q2.push(a);
    }
    if(flag)
        printf("success.\n");
    else
        printf("invalid priority.\n");
    jiaohuan();
}
void o8()
{
    if(top!=-1)
    {
        printf("success.\n");
        top=-1;
    }
    else
        printf("no such person.\n");
}
void o9()
{
    clear2();
    while(!q1.empty())
    {
        node a=q1.front();
        q1.pop();
         //printf("--->Bye %d: %d\n",a.num,a.res);
        if(top==a.num)
        {
            if(a.res)
                printf("Bye %d: %d\n",a.num,a.res);
            continue;
        }
        q2.push(a);
    }
    while(!q2.empty())
    {
        node a=q2.front();
        q2.pop();
        if(a.res!=0)
            printf("Bye %d: %d\n",a.num,a.res);
    }
}
void sove()
{
    int i;
    for(i=0; i<8; i++)
    {
        if(s==ss[i])
            break;
    }
    i++;
    if(i!=5&&i!=8)
        scanf("%d",&u);
    //printf("--->%d\n",i);
    switch(i)
    {
    case 1:
        o1();
        break;
    case 2:
        o2();
        break;
    case 3:
        o3();
        break;
    case 4:
        o4();
        break;
    case 5:
        o5();
        break;
    case 6:
        o6();
        break;
    case 7:
        o7();
        break;
    default :
        o8();
        break;
    }
}
int main()
{
    //freopen("a.txt","r",stdin);
    int t;
    scanf("%d",&t);
    while(t--)
    {
        top=-1;
        clear2();
        int n;
        scanf("%d",&n);
        for(int i=1; i<=n; i++)
        {
            flag=0;
            printf("Operation #%d: ",i);
            cin>>s;
            //cout<<s<<endl;
            sove();
        }
        o9();
    }
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值