CF898C 求助
查看原帖
CF898C 求助
431658
冷却心月明かり楼主2022/10/31 21:47

这是什么意思,题目不是说任意顺序均可吗?

屏幕截图 2022-10-31 214027.png

Code:

#include<bits/stdc++.h>
#define LL long long
#define	Fcin \
	ios :: sync_with_stdio(0);\
	cin.tie(0); cout.tie(0)
using namespace std;
const LL N = 25;
const LL MAXS = 1e5 + 10;
LL n;
class Fri{
	private:
		LL SIZE, nxt[MAXS][30], L = 0;
		bool has[MAXS];
	
	public:
		string name;
		LL size(){
			return L;
		}
		void insert(string str){
			LL len = str.size();
			bool flag = false;
			LL now = 0;
			for (LL i = len - 1; i >= 0; i --){
				LL ch = str[i] - '0';
				if (!nxt[now][ch])
					nxt[now][ch] = ++ SIZE, now = SIZE, flag = true;
				else
					now = nxt[now][ch];
			}
			if (flag)
				has[now] = true, ++ L;
			return ;
		}
		
		void output(LL now, string res){
			bool flag = true;
			for (LL i = 0; i <= 9; i ++){
				if (nxt[now][i]){
					flag = false;
					string s = (char)(i + '0') + res;
					output(nxt[now][i], s);
				}
			}
			if (flag)
				cout << res << " ";
		}
	
}fri[N];
map<string, int> mp;
int main(){
	Fcin;
	
	LL len = 0;
	cin >> n;
	LL k;
	string str;
	for (LL i = 1; i <= n; i ++){
		cin >> str;
		LL ind;
		if (!mp.count(str)){
			ind = ++ len;
			mp[str] = len;
		}
		else 
			ind = mp[str];
		fri[ind].name = str;
		cin >> k;
		for (LL j = 1; j <= k; j ++){
			cin >> str;
			fri[ind].insert(str);
		}
	}
	for (LL i = 1; i <= len; i ++){
		cout << fri[i].name << " " << fri[i].size() << " ";
		fri[i].output(0, "");
		cout << "\n";
	}
	return 0;
}
2022/10/31 21:47
加载中...