给定一个数组,其中每个元素出现两次,除了一对(两个元素)。找到这个唯一对的元素。

输入:
第一行输入包含一个表示测试用例数的整数T。然后T测试用例如下。每个测试用例由两行组成。每个测试用例的第一行包含整数N表示数组的大小,第二行包含N个空格分隔元素。

输出:
对于每个测试用例, 在新行中以增加的顺序打印唯一对。

约束:
1 <= T <= 100 
1 <= N <= 10 3
1 <= A [i] <= 10 3

示例:
输入:


2 2 5 5 6 7 

1 3 4 1

输出:
6 7 
3 4

这个题算是最简单的一个题目,写下我的解题思路。

核心在于怎么找出来这一对元素:假设数组存放在b数组中,因为数组元素的大小是1-1000,所以新建数组a使其大小是1000,初始化为0。

依次将b中元素对应于a中的下标进行递增。如果最终a中是奇数的就是目标答案。只需要遍历一遍就可以了。

下面是具体代码实现:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int n;//具体执行几次
    scanf("%d",&n);
    int *num=(int*)malloc(sizeof(int)*n);//num数组存放每个数组的大小.
    int i,j;//i是循环变量

    ;i<n;i++)
    {
        scanf("%d\n",&num[i]);//读入第i个数组元素的个数。
        int *b=(int*)malloc(sizeof(int)*num[i]);//分配b数组空间
        ;j<num[i];j++)
            scanf("%d",&b[j]);//依次读入数组元素.
        ]={};//初始化为0
        ;j<num[i];j++)
            a[b[j]-]++;//对数组a,b进行处理。

        ;j<;j++)
        {
            ==)
                printf());
        }
        printf("\n");
    }
    ;
}

如果存在任何不理解,请留言。

Find Unique pair in an array with pairs of numbers 在具有数字对的数组中查找唯一对的更多相关文章

  1. [LeetCode] 34. Find First and Last Position of Element in Sorted Array 在有序数组中查找元素的第一个和最后一个位置

    Given an array of integers nums sorted in ascending order, find the starting and ending position of ...

  2. 【leetcode】Merge Sorted Array(合并两个有序数组到其中一个数组中)

    题目: Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assum ...

  3. [Swift]LeetCode34. 在排序数组中查找元素的第一个和最后一个位置 | Find First and Last Position of Element in Sorted Array

    Given an array of integers nums sorted in ascending order, find the starting and ending position of ...

  4. C#LeetCode刷题之#34-在排序数组中查找元素的第一个和最后一个位置(Find First and Last Position of Element in Sorted Array)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4970 访问. 给定一个按照升序排列的整数数组 nums,和一个目 ...

  5. 【LeetCode】1095. 山脉数组中查找目标值 Find in Mountain Array

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 二分查找 日期 题目地址:https://leetco ...

  6. LeetCode Search in Rotated Sorted Array 在旋转了的数组中查找

    Search in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to you before ...

  7. 28.earch in Rotated Sorted Array(排序旋转数组中查找)

    Level:   Medium 题目描述: Suppose an array sorted in ascending order is rotated at some pivot unknown to ...

  8. Leetcode34.Find First and Last Position of Element in Sorted Array在排序数组中查找元素的位置

    给定一个按照升序排列的整数数组 nums,和一个目标值 target.找出给定目标值在数组中的开始位置和结束位置. 你的算法时间复杂度必须是 O(log n) 级别. 如果数组中不存在目标值,返回 [ ...

  9. [LeetCode] K-diff Pairs in an Array 数组中差为K的数对

    Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in t ...

随机推荐

  1. 【javaFX学习】(二) 面板手册--1

    找了好几个资料,没找到自己想要的,自己写个列表吧,方便以后用的时候挑选,边学边记.以学习笔记为主,所以会写的会偏个人记忆性.非教程,有什么问题一起讨论啊. 各个不同的控件放入不同的面板中有不同的效果, ...

  2. devdependencies与dependencies的区别

    一直在纠结devdependencies与dependencies的区别是什么,下面就对此作出详细介绍,希望对你有所帮助! 我们在使用npm install 安装模块或插件的时候,有两种命令把他们写入 ...

  3. 工厂模式(Factory Method)

    1.工厂方法模式(Factory Method) 工厂方法模式分为三种: 1-1.普通工厂模式,就是建立一个工厂类,对实现了同一接口的一些类进行实例的创建. 举例如下:(我们举一个发送邮件和短信的例子 ...

  4. FreeRTOS--堆内存管理

    因为项目需要,最近开始学习FreeRTOS,一开始有些紧张,因为两个星期之前对于FreeRTOS的熟悉度几乎为零,经过对FreeRTOS官网的例子程序的摸索,和项目中问题的解决,遇到了很多熟悉的身影, ...

  5. MySQL学习——基本命令(1)

    MySQL添加新用户.为用户创建数据库.为新用户分配权限 参考博客http://blog.csdn.net/u013216667/article/details/70158452 一.登录MySQL ...

  6. Python---初识堡垒机

    在学习堡垒机之前,我们需要首先了解下Python的paramiko模块,该模块机遇SSH用于连接远程服务器并执行相关操作. SSHClient 用于连接远程服务器并执行基本命令 基于用户名密码连接: ...

  7. 初识AOP与动态代理

    AOP AOP是指在jvm运行时, 动态将代码切入到指定位置. OOP是一个维度上写代码, AOP是把他切开来, 变成立体的. 这样的好处是: 业务逻辑跟辅助逻辑分离, 例如日志打印, 性能监控, 安 ...

  8. CS Round#49 C Max Substring

    Max Substring Time limit: 1000 msMemory limit: 256 MB   You are given a string S. Find a string T th ...

  9. 【new File(String Path)加载资源问题】

    2017-12-17   15:07:38  [原创-wx] 一.我们在用IO流加载资源的时候,创建文件资源 1 File file = New File("String Path" ...

  10. 如何在你的blog中添加炫酷的飘雪动画效果

    将下面的代码复制到你的设置栏下页眉html代码框中即可 <script> (function($){$.fn.snow=function(options){,maxSize:,newOn: ...