本题测试数据和题意不匹配
2020.10.17记录,后续牛客会不会改测试数据不知道
一、用哈希进行排序
#include<bits/stdc++.h>
using namespace std;
int _hash[5000+5];
int main()
{
int n,m;
while( ~scanf("%d%d",&n,&m) )
{
memset(_hash,0,sizeof(_hash));
for(int i=0 ;i<n; ++i)
{
int temp;
scanf("%d",&temp);
_hash[temp]++;
}
for(int i=0 ;i<m; ++i)
{
int temp;
scanf("%d",&temp);
_hash[temp]++;
}
for(int i=0 ;i<5005; ++i)
{
while( _hash[i]-- )
{
printf("%d ",i);
}
}
printf("\n");
}
return 0;
} 提交显示
段错误 Case:90%
然后,我就纳闷了,哈希没有数组越界,而且很显然这么简单的代码没错
后面想了想,除非题目说的
n个整数(范围1~5000)
这句话有误,才可能导致我的哈希数组越界,然后,我就只能猜。。。是不是5000少打了个0,然后,改50005的哈希数组,AC了
二、最终AC代码
#include<bits/stdc++.h>
using namespace std;
int _hash[500005];
int main()
{
int n,m;
while( ~scanf("%d%d",&n,&m) )
{
memset(_hash,0,sizeof(_hash));
for(int i=0 ;i<n; ++i)
{
int temp;
scanf("%d",&temp);
_hash[temp]++;
}
for(int i=0 ;i<m; ++i)
{
int temp;
scanf("%d",&temp);
_hash[temp]++;
}
for(int i=1 ;i<50001; ++i)
{
while( _hash[i]-- )
{
printf("%d ",i);
}
}
printf("\n");
}
return 0;
} 
京公网安备 11010502036488号