解法一:

map

1.45 ms

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std; int main()
{
int temp;
map<int, int> mapping;
while (scanf("%d", &temp) != EOF)
{
mapping[temp]++;
}
for (map<int, int>::iterator it = mapping.begin(); it != mapping.end(); it++)
{
if (it->second == )
{
printf("%d", it->first);
}
}
system("pause");
return ;
}

解法二:

因为题目提出“其中仅有一个数字出现过一次,其他数字均出现过两次”,即可以利用异或计算

一个数字异或它自己结果为0,异或0结果为它自己即a^a=0,a^0=a,且异或满足a^b^c=a^(b^c)。

因此我们可以设置一个ret异或每个元素,最后相同的都抵消为0,那个唯一的数字异或0为它自己即为答案。

1.97 ms

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std; int main()
{
int temp;
int arr[];
int i = ;
while (scanf("%d", &temp) != EOF)
{
arr[i] = temp;
i++;
}
int ret = ;
for (int j = ; j < i; j++)
{
ret ^= arr[j];
}
printf("%d",ret);
system("pause");
return ;
}

[小米OJ] 2. 找出单独出现的数字的更多相关文章

  1. 【小米oj】找出单独的数字

    题目链接:https://code.mi.com/problem/list/view?id=2&cid=0&sid=26251#codearea 描述 给出N个数字.其中仅有一个数字出 ...

  2. [小米 Online Judge]找出单独出现的数字

    描述: 给出N个数字.其中仅有一个数字出现过一次,其他数字均出现过两次,找出这个出现且只出现过一次的数字.要求时间和空间复杂度最小. 输入: 输入多个数字,每个数字以空格分开,回车结束 输出: 输出内 ...

  3. 小米OJ 12. 找出可能的合的组合

    利用dfs解决,从给出的数组左边或右边开始遍历,对每一个数字进行判断,有三种情况: 1. 加上当前数字的值,遍历下一个数字 2. 加上当前数字的值,继续遍历该数字 3. 不加上当前的数字的值,遍历下一 ...

  4. [小米OJ] 5. 找出旋转有序数列的中间值

    排序,输出 #include <bits/stdc++.h> using namespace std; int main() { string input; while (cin > ...

  5. 剑指Offer38 数组所有数字出现两次,只有两个出现了一次,找出这两个数字

    /************************************************************************* > File Name: 38_Number ...

  6. Java初学者作业——编写Java程序,在控制台中输入一个数字,要求定义方法实现找出能够整除该数字的所有数字。

    返回本章节 返回作业目录 需求说明: 编写Java程序,在控制台中输入一个数字,要求定义方法实现找出能够整除该数字的所有数字. 实现思路: 定义方法findNums(),用于实现查找所有能够整除指定数 ...

  7. 九度OJ 1035:找出直系亲属(二叉树)

    题目1035:找出直系亲属 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1309 解决:521 题目描述: 如果A,B是C的父母亲,则A,B是C的parent,C是A,B的child,如 ...

  8. 15. 3Sum_左右开工,遍历找出符合目标的数字

    题目: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find al ...

  9. 【SQLSERVER】如何找出字符串中的数字

    可以通过写自定义函数实现,以下提供两种思路来解决: 1.通过正则匹配,找到字符串中的数字,一个一个拼起来 /*方法一: 一个一个找出来*/ CREATE FUNCTION [dbo].[Fun_Get ...

随机推荐

  1. delphi控件安装(安装ODAC、TeeChart、TServerSocket、TWSocketServer、TComm)

    一.oracle插件安装delphi7如何安装oracle access控件 假设ODAC主目录在 D:\dzj\odac Delphi7主目录在 D:\Program Files\Borland\D ...

  2. Qt4.85静态编译配置VS动态编译(非常详细的图文教程)

    http://www.qter.org/forum.php?mod=viewthread&tid=1409&extra=page%3D1&page=1

  3. Dedecms 中,获取某一栏目所有子栏目

    以前从来没写过递归(其实想想,对算法完全没概念),刚好有这个需求,试着写了一下,发现也挺容易的,特别记录一下. 数据库是dedecms默认的,dede_arctype是保存栏目的表,reid是栏目的父 ...

  4. 解除.NET中虚拟路径的疑惑

    今天部署产品时,发现一个涉及到路径错误的bug,在开发环境下都OK,但是到了测试环境中却一直报错,经过一番排查,原来错误出在了HttpContext.Current.Server.MapPath这个方 ...

  5. hdu4616_Game_树形DP

    以为很水的一道题,花了大半天的时间才搞定,比赛的时候卡在这题上了,伤不起啊... 题意:给一棵树,每个结点中有礼物,每个礼物有一个权值,某些结点中会有陷阱,你可以从任何一点出发,每个结点最多只能经过一 ...

  6. oracle10g登录em后,提示“java.lang.Exception: Exception in sending Request :: null”

    出现错误时登录企业管理器时出现的界面 出现这种错误一般是因为没有设置时区,一般默认的是agentTZRegion=GMT,也就是GMT.所以大家只要设置了这个东西,然后重新启动dbconsole就可以 ...

  7. PWN菜鸡入门之CANARY探究

    看门见码 #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <strin ...

  8. 【转+存】JVM指令集

    jvm指令集: 转载地址:https://www.cnblogs.com/yaoyinglong/p/4300447.html 一.未归类系列A 此系列暂未归类. 指令码    助记符         ...

  9. vim配置轻量级IDE

    安装VIM 安装YouCompleteMe的时候, 需要VIM的版本比较高, 一般一些Linux长期支持版的Vim包就比较老, 所以可能需要编译安装. 卸载之前系统中安装的版本: CentOS/Fed ...

  10. Programming In Lua 第八章

    1, 也就是说,lua虽然会把代码预编译成中间码,以提高运行速度.但其会在程序运行过程中需要编译器,所以其仍然是解释型语言.loadfile会加载一个文件并将其编译成中间码,并返回一个函数. 2, 3 ...