bupt 84 Single Number(水题)

539人阅读 评论(0) 收藏 举报
分类:

思路:排个序然后扫一遍即可


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
const int maxn = 100000+100;
LL a[maxn];
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
         for(int i = 1;i<=n;i++)
			 scanf("%lld",&a[i]);
		 sort(a+1,a+1+n);

		 for(int i = 1;i<=n;i+=3)
		 {
             if(a[i]==a[i+1]&&a[i+1]==a[i+2])
				 continue;
			 else
			 {
				 printf("%lld\n",a[i]);
				 break;
			 }
		 }
	}
}


时间限制 1000 ms 内存限制 65536 KB

题目描述

Given an array with N integers where all elements appear three times except for one. Find out the one which appears only once.

输入格式

Several test cases are given, terminated by EOF.

Each test case consists of two lines. The first line gives the length of array N(1N105), and the other line describes the Nelements. All elements are ranged in [0,2631].

输出格式

Output the answer for each test case, one per line.

输入样例

4
1 1 1 3
10
1 2 3 1 2 3 1 2 3 4

输出样例

3
4

查看评论

好题 BUPT OJ84 SINGLE NUMBER

题目描述 Given an array with N integers where all elements appear three times except for one. Find ou...
  • samuelwyf
  • samuelwyf
  • 2014-02-26 10:44:36
  • 2443

北邮oj 84 single number

时间限制 1000 ms 内存限制 65536 KB 题目描述 Given an array with N integers where all elements appear three t...
  • sacainiao
  • sacainiao
  • 2016-03-03 09:22:05
  • 1026

Single Number

Single Number I Given an array of integers, every element appears twice except for one. Find that ...
  • hongya1109110121
  • hongya1109110121
  • 2015-03-03 21:11:30
  • 1246

北邮OJ 84. Single Number

84. Single Number 时间限制 1000 ms     内存限制 65536 KB     题目描述 Given an array with N  integers wher...
  • u012662688
  • u012662688
  • 2016-03-10 09:58:07
  • 1064

LeetCode || Single Number II

Single Number II  Total Accepted: 12144 Total Submissions: 37399My Submissions Given an ...
  • jiadebin890724
  • jiadebin890724
  • 2014-04-09 23:35:07
  • 19120

[LC260]Single Number III

260. Single Number III Given an array of numbers nums, in which exactly two elements appear only o...
  • u012460028
  • u012460028
  • 2016-06-28 12:21:30
  • 156

bupt 84 Single Number(水题)

思路:排个序然后扫一遍即可 #include #include #include using namespace std; #define LL long long const int ma...
  • qq_21057881
  • qq_21057881
  • 2016-06-01 22:51:12
  • 539

kAri OJ84 Single Number(强大的位运算)

84. Single Number 时间限制 1000 ms 内存限制 65536 KB 题目描述 Given an array with N integers wher...
  • opm777
  • opm777
  • 2016-03-13 22:11:39
  • 1159

#84 Single Number III

题目描述: Given 2*n + 2 numbers, every numbers occurs twice except two, find them. Have yo...
  • haifischxia
  • haifischxia
  • 2016-08-15 09:54:20
  • 55

LeetCode之Array题目汇总

Two SumGiven an array of integers, find two numbers such that they add up to a specific target numbe...
  • Yano_nankai
  • Yano_nankai
  • 2015-12-23 19:28:39
  • 3389
    个人资料
    持之以恒
    等级:
    访问量: 36万+
    积分: 1万+
    排名: 1109
    最新评论