Singal Num (i)

Source: Internet
Author: User

Title Description

Given an array, the remaining number appears 2 times, except for a number that occurs 1 times. Find out the number that appears once.

For example: {1, 2, 1, 2, 1, 2, 7}, find 7.

Enter a description

The first line enters a number n, which represents the length of the array, and the next line enters n integers representing the array a[n].

Output description

The output appears only once in number.

Input sample

4 0 0 5 5 7

Output sample

7

Problem analysis

When all the numbers in the array are different or up, each pair will have a number of 0, and then the last number left is the number that only 1 times.

Test code

1#include <stdio.h>2#include <stdlib.h>3 4 intMainvoid)5 {6     intn, I, *arr;7 8scanf"%d", &n);9Arr = (int*)malloc(n *sizeof(int));Tenscanf"%d", arr); One      for(i =1; I < n; i++) A     { -scanf"%d", arr +i); -arr[0] ^=Arr[i]; the     } -printf"%d\n", arr[0]); -  -      Free(arr); +     return 0; -}

Singal Num (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.