P4896 Oier们的烦恼

很随意的字符串模拟题

题外话:样例很良心!

这道题就直接看题意做就可以了。不要管其他花里胡哨的话,直接照点去做就可以了。

因为数据范围真的小,所以可以直接用string,甚至可以用stringstream来做!

不知道为什么是TG+难度啊。

代码:

#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
using namespace std;

string teacher[4], student[6];
bool gg[6], playing[6];
int cnt;
bool have_teacher;
int n;
vector<string> vec;

int which_teacher(string x)
{
    for(int i = 1; i <= 3; i++) if(x == teacher[i]) return i;
    return 0;
}
int which_student(string x)
{
    for(int i = 1; i <= 5; i++) if(x == student[i]) return i;
    return 0;
}
int main()
{
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i = 1; i <= 3; i++) cin >> teacher[i];
    for(int i = 1; i <= 5; i++) cin >> student[i];
    string now;
    getline(cin, now);
    for(int i = 1; i <= n; i++)
    {
        getline(cin, now);
        stringstream ss(now);
        string temp;
        ss >> temp;
        int kind1 = which_teacher(temp), kind2 = which_student(temp);
        if(kind1)
        {
            ss >> temp;
            if(temp == "came!")
            {
                have_teacher = true;
                for(int i = 1; i <= 5; i++)
                {
                    if(playing[i])
                    {
                        gg[i] = true;
                    }
                }
            }
            else if(temp == "left!")
            {
                have_teacher = false;
                
            }
        }
        else if(kind2)
        {
            ss >> temp;
            if(temp == "started")
            {
                ss >> temp;
                if(temp == "playing")
                {
                    ss >> temp;
                    if(temp == "games!")
                    {
                        playing[kind2] = true;
                        if(have_teacher)
                        {
                            gg[kind2] = true;
                        }
                    }
                }
            }
            else if(temp == "stopped")
            {
                ss >> temp;
                if(temp == "playing")
                {
                    ss >> temp;
                    if(temp == "games!")
                    {
                        playing[kind2] = false;
                    }
                }
            }
        }
    }
    for(int i = 1; i <= 5; i++) if(gg[i]) vec.push_back(student[i]), cnt++;
    std::sort(vec.begin(), vec.end());
    for(vector<string>::iterator it = vec.begin(); it != vec.end(); ++it)
    {
        cout << *it << ' ';
    }
    if(!vec.empty()) cout << endl;
    if(cnt == 5) cout << "How Bad Oiers Are!" << endl;
    else if(cnt == 0) cout << "How Good Oiers Are!" << endl;
    return 0;
}
posted @ 2018-11-04 21:00  Garen-Wang  阅读(169)  评论(0编辑  收藏  举报