解法一:

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. RESTful API设计原则与规范

    RESTful API设计原则与规范 一.背景与基础概念 2 二.RESTful API应遵循的原则 3 1.协议(Protocol) 3 2.域名(ROOT URL) 3 3.版本(Versioni ...

  2. How Qt Signals and Slots Work(感觉是通过Meta根据名字来调用)

    Qt is well known for its signals and slots mechanism. But how does it work? In this blog post, we wi ...

  3. QT5.7静态编译(使用VS2013与VS2015编译,XP可用,有详细configure脚本。VS下Qt插件的配置。编译选项加上-mp可以开启多线程编译,编译速度提高2倍以上)

    http://blog.csdn.net/u011964923/article/details/52886908 configure -confirm-license -opensource -pla ...

  4. 【安装】Hadoop2.8.0搭建过程整理版

    Hadoop搭建过程 前期环境搭建主要分为软件的安装与配置文件的配置,集成的东西越多,配置项也就越复杂. Hadoop集成了一个动物园,所以配置项也比较多,且每个版本之间会有少许差异. 安装的方式有很 ...

  5. 开源joda-time使用demo

    开源joda-time 1.maven中引入 <dependency> <groupId>joda-time</groupId> <artifactId> ...

  6. Asp.net HttpClient Proxy(Fiddler)

    <system.net> <defaultProxy> <proxy bypassonlocal="False" usesystemdefault=& ...

  7. Spring Boot2(六):使用Spring Boot整合AOP面向切面编程

    一.前言 众所周知,spring最核心的两个功能是aop和ioc,即面向切面和控制反转.本文会讲一讲SpringBoot如何使用AOP实现面向切面的过程原理. 二.何为aop ​ aop全称Aspec ...

  8. Jenkins Email Extension插件模板

    Jenkins Email Extension插件模板 <!DOCTYPE html> <html> <head> <meta charset="U ...

  9. 使用 cxf的程序 在win10 测试部署时报空指针异常

    2018-11-08 15:50:55.072 DEBUG 21524 --- [nio-8080-exec-1] o.s.b.w.s.f.OrderedRequestContextFilter  : ...

  10. 50道SQL练习题及答案与详细分析!!!

    以前在学校还没有很认真地意识到,现在到了企业才发现sql是那么的重要,看到网上有很多的sql 练习题,特地拿来练练手! 数据表介绍 --1.学生表 Student(SId,Sname,Sage,Sse ...