50pts求调
查看原帖
50pts求调
724676
Iwara_qwq楼主2022/10/4 16:02
#include<bits/stdc++.h>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const ll INF=0x7f7f7f7f7f,inf=0x3f3f3f3f3f;
namespace Yorihime_Nao{
	template<class T> T MAX(T x,T y){
		return x>y?x:y;
	}
	template<class T> T MIN(T x,T y){
		return x<y?x:y;
	}
	template<class T,class ... Arg> T MAX(T x,T y,Arg ... arg){
		return MAX(x>y?x:y,arg...);
	}
	template<class T,class ... Arg> T MIN(T x,T y,Arg ... arg){
		return MIN(x<y?x:y,arg...);
	}
	template<class T> T lowbit(T x){
		return x&-x;
	}
	template<class T> void SWAP(T &x,T &y){
		T qwq=x;
		x=y;
		y=qwq;
		return;
	}
}
using namespace Yorihime_Nao;
ll n;
map<string, vector<string> > mp; 
string s;
void solve(string str){
//	cout<<str<<" <<"<<endl;
	if(mp[str].empty()){
		cout<<str;
		return;
	}
	if(mp[str][0]=="Yorihime_Nao")return;
	ll cnt=0;
	for(string reg:mp[str]){
		cnt++;
		if(cnt>1)cout<<" ";
		solve(reg);
	}
	return;
}
int main(){
	freopen("preprocessor.in","r",stdin);
	freopen("preprocessor.out","w",stdout);
	cin>>n;
	getchar();
	for(int i=1;i<=n;i++){
		ll cnt=0,pos=0;
		string reg,tmp;
		ll fl=0;
		getline(cin,s);
		ll len=s.size();
//		cout<<"len: "<<len<<endl;
		while(1){
			reg="";
			while(s[pos]!=' '&&pos<len)reg+=s[pos++];
			if(reg=="")break;
//			cout<<reg<<" <<\n";
			pos++;
			cnt++;
//			cout<<"cnt: "<<cnt<<endl;
			if(cnt==1&&reg[0]=='#'){
				if(reg[1]=='d')fl=1;
				else fl=2;
				continue;
			}
//			cout<<"fl: "<<fl<<endl;
			if(fl!=0){
				if(cnt==2)tmp=reg;
				else{
					mp[tmp].push_back(reg);
//					cout<<"pushed: "<<reg<<endl; 
				}
			}
			else if(fl==0){
				ll L=reg.size();
				ll qwq=0;
				char awa='@';
				if(reg[L-1]==';'||reg[L-1]==',')awa=reg[L-1],reg=reg.substr(0,L-1),qwq=1;
				solve(reg);
//				cout<<endl;
//				cout<<awa<<endl;
				if(awa!='@')cout<<awa;
				cout<<" ";
			}
//			cout<<"tmp: "<<tmp<<endl;
		}
		if(fl==1&&cnt==2)mp[tmp].push_back("Yorihime_Nao");
		if(fl==2)mp[tmp].clear();
		cout<<endl;
	}
	return 0;
}

2022/10/4 16:02
加载中...