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!
  • 相关阅读:
    lintcode491 回文数
    lintcode514 栅栏染色
    lintcode433 岛屿的个数
    lintcode142 O(1)时间检测2的幂次
    lintcode166 链表倒数第n个节点
    lintcode539 移动零
    lintcode: Check Sum of Square Numbers
    lintcode: Missing String
    lintcode 二叉树的锯齿形层次遍历
    Mysql 游标的定义与使用方式
  • 原文地址:https://www.cnblogs.com/VictorierJwr/p/12775252.html
Copyright © 2011-2022 走看看