异或的经典运用hdu2095

来源:互联网 发布:秀太捏脸数据 编辑:程序博客网 时间:2024/05/18 01:45

题目就不说了,下面是我的代码:

#include<iostream>#include<cstdio>using namespace std;int main(){    int reasult=0,numeber,n,m;    while(scanf("%d",&n)!=EOF&&n)    {        reasult=0;        while(n--)        {            scanf("%d",&m);            reasult=reasult^m;        }        printf("%d\n",reasult);    }    return 0;}

很少有地方解释为什么用异或,好吧,我智商不高,不知道,后来有解释为什么用异或。因为奇数次的异或为1,偶数次异或为0,还有,异或满足交换律,就是这样了。。^_^

0 0
原创粉丝点击