甚至错的很规矩,都是实际输出比理想输出大了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;
}
用链表解决地址冲突问题