求助
  • 板块灌水区
  • 楼主somek_
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/11/25 08:58
  • 上次更新2023/11/25 08:59:50
查看原帖
求助
1037054
somek_楼主2023/11/25 08:58

题目

代码:

#include <bits/stdc++.h>
using namespace std;
map<string, string>M;

string find(string x) {
	while (M[x] != x)
		x = M[x];
	return x;
}

void family(string x, string y) {
	x = find(x);
	y = find(y);
	if (x != y)
		M[x] = y;
}

int main() {
	string s, fa;
	while (cin >> s) {
		if (s[0] == '$')
			break;
		if (s[0] == '#')
			fa = s.substr(1);
		if (s[0] == '+')
			family(fa, (s.substr(1)));
		if (s[0] == '?')
			cout << s.substr(1) << " " << find((s.substr(1))) << "\n";
	}
}

为什么我的代码中的祖先都是空格啊

2023/11/25 08:58
加载中...