B3982求救
  • 板块灌水区
  • 楼主fhy2023
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/7/5 18:32
  • 上次更新2024/7/5 20:26:58
查看原帖
B3982求救
1032487
fhy2023楼主2024/7/5 18:32
#include<bits/stdc++.h>
#define int long long
using namespace std;
namespace IO
{
	#define p putchar
	#define g getchar
	inline int read()
	{
		int s=0,f=1;
		char ch=g();
		while(!('0'<=ch&&ch<='9'))
		{
			if(ch=='-')
			{
				f=-1;
			}
			ch=g();
		}
		while('0'<=ch&&ch<='9')
		{
			s=s*10+ch-'0';
			ch=g();
		}
		return s*f;
	}
	inline void write(int x)
	{
		if(x<0)
		{
			p('-');
			x=-x;
		}
		if(x<10)
		{
			p(x+'0');
		}
		else
		{
			write(x/10);
			p(x%10+'0');
		}
	}
	#undef p
	#undef g
}
using IO::read;
using IO::write;
string bt[110];
map<string,int>mp;
int cnt=0;
struct ji
{
	string a[110];
}ac[110];
string yj[110000];
int cn=0;
inline bool cmp(ji x,ji y)
{
	for(int i=1;i<=cn;i++)
	{
		char z=yj[i][yj[i].size()-1];
		int size=yj[i].size()-1;
		string a="";
		for(int j=0;j<size;j++)
		{
			a+=yj[j];
		}
		if(x.a[mp[a]]==y.a[mp[a]])
		{
			continue;
		}
		else
		{
			return z=='+'?x.a[mp[a]]<y.a[mp[a]]:x.a[mp[a]]>y.a[mp[a]];
		}
	}
}
signed main()
{
	int n=read();
	n--;
	char ch=getchar();
	string x="";
	while(ch!='\n')
	{
		if(ch==',')
		{
			bt[++cnt]=x;
			mp[x]=cnt;
			x="";
			ch=getchar();
			continue;
		}
		x+=ch;
		ch=getchar();
	}
	bt[++cnt]=x;
	mp[x]=cnt;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=cnt;j++)
		{
			char ch=getchar();
			string x="";
			while(ch!=','&&ch!='\n')
			{
				x+=ch;
				ch=getchar();
			}
			ac[i].a[j]=x;
		}
	} 
	int m=read();
	for(int i=1;i<=m;i++)
	{
		string x;
		cin>>x;
		yj[++cn]=x;
	}
	sort(ac+1,ac+n+1,cmp);
	for(int i=1;i<=cnt;i++)
	{
		cout<<bt[i];
		if(i!=cnt)
		{
			putchar(',');
		}
	}
	cout<<endl;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=cnt;j++)
		{
			cout<<ac[i].a[j];
			if(j!=cnt)
			{
				putchar(',');
			}
		}
		putchar('\n');
	}
	return 0;
}

这道题用这个代码一直RE 求大佬解释一下

2024/7/5 18:32
加载中...