为什么会这样?求助dalao
  • 板块P2814 家谱
  • 楼主__Emerald__
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/6/28 21:28
  • 上次更新2023/11/3 12:12:27
查看原帖
为什么会这样?求助dalao
556181
__Emerald__楼主2023/6/28 21:28

代码:

#include <bits/stdc++.h>
using namespace std;
const int SIZE = 70001;
struct node{
	string data;
	int fa;
};
node hash[SIZE];
int i,t;
string s,father,child;
int h(string s){
	int i,ans = 0;
	for (i = 0;i < s.length();i++) ans = ans + s[i] * s[i];
	ans = ans % SIZE;
	return ans;
}
int search(string s){
	int t = h(s);
	while (hash[t].data != s && hash[t].data != "") t++;
	return t;
}
void insert(string father,string child){
	int temp = search(father),p;
	if (hash[temp].data != father) hash[temp].data = father,hash[temp].fa = 0;
	p = search(child),hash[p].data = child,hash[p].fa = temp;
}
int main(){
	for (int i = 0;i <= SIZE - 1;i++) hash[i].data = "",hash[i].fa = 0;
	cin >> s;
	do{
		father = s.substr(1,6);
		do{
			cin >> s;
			if (s[0] != '+') break;
			child = s.substr(1,6);
			insert(father,child);
		}while (s[0] == '+');
	}while (s[0] != '?'); 
	while (s[0] != '$'){
		s = s.substr(1,6),t = search(s);
		while (hash[t].fa != 0) t = hash[t].fa;
		cout << s << ' ' << hash[t].data << endl;
		cin >> s;
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}

为什么编译不通过?在自己的编译器上试后,结果: https://cdn.luogu.com.cn/upload/image_hosting/dxspgrzj.png

2023/6/28 21:28
加载中...