1 条题解

  • 0
    @ 2025-8-24 22:05:02

    自动搬运

    查看原文

    来自洛谷,原作者为

    avatar ⑨baka
    **

    搬运于2025-08-24 22:05:02,当前版本为作者最后更新于2018-10-27 02:09:05,作者可能在搬运后再次修改,您可在原文处查看最新版

    自动搬运只会搬运当前题目点赞数最高的题解,您可前往洛谷题解查看更多

    以下是正文


    题目地址

    前言

    这道题虽然很水但耗费了我一个多小时去调试...可能是我太弱了吧..还有测试数据3是什么鬼

    Solution

    此题就是一道模拟题...只要按照题目的意思模拟即可。但这道题也有一些坑点,比如getline多出来的空格,或者是打名字时多出来的回车...在这里我用了一种特殊的方法,就是什么也不判断

    详见代码。

    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<cstdio>
    using namespace std;
    #define M 114514
    string teacher[4],stu[6],s;
    char s1[M],stop_play[110]={" stopped playing games!"};
    char start_play[110]={" started playing games!"};
    char come[110]={" came!"},l[110]={" left!"};//char字符在全局变量里定义为空格...所以如果gets有多出空格的话是不需要判断的
    bool a[11],comes,play[11];
    int len,n;
    int main()
    {
        cin>>n;
        for(int i=1;i<=3;++i)
            cin>>teacher[i];
        for(int i=1;i<=5;++i)
            cin>>stu[i];
        sort(stu+1,stu+6); //题目中要求按字典序
        for(int i=1;i<=n;++i)
        {
            cin>>s; //cin以空格为结束符号 所以可以用来判断此题中的学生名字或老师名字,并且也可以避免
            gets(s1); //gets以回车作为结束符号
            for(int j=1;j<=3;++j)
                if(s==teacher[j])
                {
                    if(!strcmp(s1,come)) comes=1;//按题意模拟
                    if(!strcmp(s1,l)) comes=0;
                }
            for(int j=1;j<=5;++j)
                if(s==stu[j])
                {
                    if(!strcmp(s1,stop_play)) play[j]=0; //strcmp函数判断两字符串是否相同
                    if(!strcmp(s1,start_play)) play[j]=1;
                }
            if(comes==1) //当老师在的时候判断学生们是否在打游戏
            {
                for(int j=1;j<=5;++j)
                    if(play[j] && !a[j])
                    {
                        ++len;
                        a[j]=1; //标记一下...
                    }
            }
            if(len==5) break;
        }
        for(int i=1;i<=5;++i)
            if(a[i]==1)
                cout<<stu[i]<<" ";
        if(len==0) cout<<"How Good Oiers Are!";
        if(len==5) cout<<endl<<"How Bad Oiers Are!";
        return 0;
    }
    

    据大佬们说此题还可以用string.erase来解决...不过我太弱不会

    • 1

    信息

    ID
    3771
    时间
    1000ms
    内存
    512MiB
    难度
    2
    标签
    递交数
    0
    已通过
    0
    上传者