跳到正文

题解

题解 P4896 【Oier们的烦恼】

muller约 4 分钟
原文
文章信息与版本

文章信息

发布
2019年2月17日
收录
2025年12月12日
更新
2026年11月16日
篇幅
约 4 分钟
题目
P4896

版本

  1. v1当前

这题模拟即可

但是注意中间好像有回车

毒瘤

竟然没发现

所以要getline一下

否则读入re qwq

于是就用随便一个容器标记一下

anyway,就可以了

注意读入。。。。

C++
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int q,t,cnt=0;
map<string,bool>mps,mpt,mpans,play;
string s1,s2,s3,s4,s5,t1,t2,t3,ans[10];
bool te=false;
void work(){
	if (play[s1]){
		if (!mpans[s1]){mpans[s1]=true;ans[++cnt]=s1;}
	}
	if (play[s2]){
		if (!mpans[s2]){mpans[s2]=true;ans[++cnt]=s2;}
	}
	if (play[s3]){
		if (!mpans[s3]){mpans[s3]=true;ans[++cnt]=s3;}
	}
	if (play[s4]){
		if (!mpans[s4]){mpans[s4]=true;ans[++cnt]=s4;}
	}
	if (play[s5]){
		if (!mpans[s5]){mpans[s5]=true;ans[++cnt]=s5;}
	}
}
int main(){
	std::ios::sync_with_stdio(false);
	cin>>q;t=q+1;cin>>t1;cin>>t2;cin>>t3;
	mpt[t1]=mpt[t2]=mpt[t3]=true;
	cin>>s1;cin>>s2;cin>>s3;cin>>s4;cin>>s5;
	mps[s1]=mps[s2]=mps[s3]=mps[s4]=mps[s5]=true;
	while (t--){
		string s;
		getline(cin,s);
		if (t==q) continue;
		int f=s.find("came!");
		if (f!=-1){
			s.erase(f);
			while (s[s.size()-1]==' ') s.erase(s.size()-1);
			if (!mpt[s]) continue;
			te=true;work();
		}
		else {
			f=s.find("left!");
			if (f!=-1){
				s.erase(f);
				while (s[s.size()-1]==' ') s.erase(s.size()-1);
				if (!mpt[s]) continue;
				te=false;
			}
			else {
				f=s.find("started playing games!");
				if (f!=-1){
					s.erase(f);
					while (s[s.size()-1]==' ') s.erase(s.size()-1);
					if (!mps[s]) continue;
					play[s]=true;
					if (te){
						if (!mpans[s]){mpans[s]=true;ans[++cnt]=s;}
					}
				}
				else {
					f=s.find("stopped playing games!");
					if (f==-1) continue;
					s.erase(f);
					while (s[s.size()-1]==' ') s.erase(s.size()-1);
					if (!mps[s]) continue;
					play[s]=false;
				}
			}
		}
	}
	if (!cnt) cout<<"How Good Oiers Are!\n";
	else {
		sort(ans+1,ans+cnt+1);
		for (int i=1;i<=cnt;i++) cout<<ans[i]<<(i==cnt ? '\n' : ' ');
		if (cnt==5) cout<<"How Bad Oiers Are!\n";
	}
	return 0;
}
原文
存档评论3 条抓取于