我先写一下我的代码:
#include <iostream>
using namespace std;
const int MAX = 1000000;
short shash[MAX] = {};
int main()
{
int t = 0;
while(t != -1)
{
cin >> t;
shash[t] = 1;
}
t = 0;
//如果hash表中数据为1,说明已经保存过了,此时将hash中的数据变为2
while(t != -1)
{
cin >> t;
if(shash[t])
{
shash[t] = 2;
}
}
int flag = 0;
for(int i = 0;i < MAX;i++)
{
if(shash[i] >= 2) //判断,如果等于2,就输出数字
{
if(flag == 1)
cout << " ";
flag = 1;
cout << i;
}
}
if(flag == 0)cout << "NULL";
return 0;
}
这道题目我没有采用链表,而是用普通数组作的,大致思路就是用散列表存储某个是否出现过,但是在PTA上的实际测试中,前五个数据都过了,但是最后一个数据(**大规模数据**)通过,显示**段错误**,请问是我的代码问题吗?