题解 | #明明的随机数#
明明的随机数
http://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
纯C 哈希表查重
int main(void)
{
int n;
while(scanf("%d\n",&n)!=EOF)
{
int str[500] = {0};
int hash[256] = {0};//哈希表
for(int i = 0;i < n;i++)
{
scanf("%d\n",&str[i]);
if(hash[str[i]] == 0)//生成重复数列表
{
hash[str[i]] = 1;
}
else if(hash[str[i]] == 1)
{
str[i] = 0;
}
}
for(int i = 0;i < n;i++)//冒泡排序
for(int j = 0; j < n; j++)
{
int temp;
if(str[i] < str[j])
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
for(int i = 0; i<n;i++)//不重复即输出
{
if(str[i] != 0)
printf("%d\n",str[i]);
}
}
}