zoukankan      html  css  js  c++  java
  • 55 删除数组重复元素

    55 删除数组重复元素

    作者: Turbo时间限制: 1S章节: 一维数组

    问题描述 :

    已有一维数组,存储不超过100个整型数据,其中有些元素的值存在重复,从数组中删除所有重复的元素(每个元素只保留一个),并输出结果数组。

    输入说明 :

    用户可输入多组数据,每组数据由两行组成:

    第一行:数组元素的个数n

    第二行:n个数组元素,由空格分隔

    输出说明 :

    对于每组输入,输出最后的结果,整数之间以空格分隔。每行的开头与结尾无多余空格。

    每组输出占一行。

    输入范例 :
    10
    1 5 4 3 2 9 7 8 6 10
    10
    1 5 5 3 2 9 7 8 6 10
    输出范例 :
    1 5 4 3 2 9 7 8 6 10
    1 5 3 2 9 7 8 6 10

    代码

    #include <stdio.h>
    #include <string.h>
    int main()
    {
    	int hash[101] = { 0 };
    	int n, m;
    	int num[101],numn=0;
    	while (scanf("%d", &n) != EOF)
    	{
    		for (int i = 0; i < n; i++)
    		{
    			scanf("%d", &m);
    			if (hash[m] == 0)
    			{
    				hash[m]++;
    				num[numn++] = m;
    			}
    		}
    		for (int i = 0; i < numn; i++)
    		{
    			printf("%d", num[i]);
    			if (i < numn - 1)
    			{
    				printf(" ");
    			}
    		}
    		printf("
    ");
    		numn = 0;
    		memset(hash, 0, sizeof(hash));
    	}
    	return 0;
    }
    
    Yesterday is history,tomorrow ismystery,but today is a gift!That why it is called Present!
  • 相关阅读:
    LeetCode 1
    Thinking in Java学习杂记(第7章)
    工程优化部分概念
    Thinking in Java学习杂记(5-6章)
    Thinking in Java学习杂记(1-4章)
    python中map()和dict()的用法
    JavaWeb高级编程(下篇)
    对CSDN的理性吐槽
    CSDN博客已经打不开了
    大连交大教务一键教学评价
  • 原文地址:https://www.cnblogs.com/VictorierJwr/p/12775252.html
Copyright © 2011-2022 走看看