zoukankan      html  css  js  c++  java
  • 一个序列,除了一个数出现两次,其他数都出现一次,找出来重复的这个数-位运算应用(异或运算)

    一个序列,除了一个数出现两次,其他数都出现一次,找出来重复的这个数-位运算应用

    面试的题目

    贴一下代码:

     1 //位运算应用
     2 #include<bits/stdc++.h>
     3 using namespace std;
     4 typedef long long ll;
     5 const int maxn=1e5+10;
     6 
     7 int n;
     8 int a[maxn];
     9 
    10 void found(){
    11     int xors=0;
    12     for(int i=0;i<n;i++){
    13         xors^= a[i];
    14     }
    15     for(int i=0;i<n;i++){
    16         xors^=i;
    17     }
    18     printf("xors= %d
    ",xors);
    19 }
    20 
    21 int main()
    22 {
    23     scanf("%d",&n);
    24     for(int i=0;i<=n;i++)
    25         cin>>a[i];
    26     found();
    27     return 0;
    28 }
    29 /*
    30 5
    31 1 2 3 4 5 5
    32 5
    33 */
  • 相关阅读:
    Many Equal Substrings CF
    Seek the Name, Seek the Fame POJ
    人人都是好朋友(离散化 + 并查集)
    建设道路
    day_30
    day_29作业
    day_29
    day_28
    day_27
    day_26作业
  • 原文地址:https://www.cnblogs.com/ZERO-/p/10457416.html
Copyright © 2011-2022 走看看