1、2、11wa求助
查看原帖
1、2、11wa求助
1293644
2320508123hzc楼主2024/8/29 16:33

甚至错的很规矩,都是实际输出比理想输出大了1,

#include<iostream>
using namespace std;
struct has {
	string str;
	has* next;
};
has * h[12345];
int main() {
	int x = 0, n, y, i, j;
	char c[1567], ch;
	has* s;
	cin >> n;
	getchar();
	for (i = 0; i < n; i++) {
		h[i] = NULL;
	}
	for (i = 0; i < n; i++) {
		y = 0;
		for (j = 0; (ch = getchar()) != '\n'; j++) {
			c[j] = ch;
			y += ch;
		}
		c[j] = '\0';
		s = h[y % n];
		while (s!= NULL) {
			if (s->str == c)break;
			s = s->next;
		}
		if (s == NULL) {
			s = new has;
			s->str = c;
			s->next = h[y % n];
			h[y % n] = s;
			x++;
		}
	}
	cout << x << endl;
	return 0;
}

用链表解决地址冲突问题

2024/8/29 16:33
加载中...