<p>
<img src="https://img-blog.csdn.net/20150429141402450?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbDU1aXVtaW5n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /></p><p><strong>一开始看到这个题目我就知道是找不同(数据中单独的一个数),然后我就想通过两个for循环一个一个比,看到n的范围 我就知道可能超时,就想到了异或运算;</strong></p><p><strong><span style="color: rgb(102, 102, 102); font-family: arial, tahoma, 'Microsoft Yahei', 宋体, sans-serif; font-size: 17.1428565979004px; line-height: 32px;">1.与1异或,可以使特定位翻转,</span><br style="color: rgb(102, 102, 102); font-family: arial, tahoma, 'Microsoft Yahei', 宋体, sans-serif; font-size: 17.1428565979004px; line-height: 32px;" /><span style="color: rgb(102, 102, 102); font-family: arial, tahoma, 'Microsoft Yahei', 宋体, sans-serif; font-size: 17.1428565979004px; line-height: 32px;">2.与0异或,保留其值</span><br style="color: rgb(102, 102, 102); font-family: arial, tahoma, 'Microsoft Yahei', 宋体, sans-serif; font-size: 17.1428565979004px; line-height: 32px;" /><span style="color: rgb(102, 102, 102); font-family: arial, tahoma, 'Microsoft Yahei', 宋体, sans-serif; font-size: 17.1428565979004px; line-height: 32px;">3.交换两值,不使用临时变量。a=a^b;b=b^a;a=a^b;</span>
</strong></p><p><strong><span style="color: rgb(102, 102, 102); font-family: arial, tahoma, 'Microsoft Yahei', 宋体, sans-serif; font-size: 17.1428565979004px; line-height: 32px;">例如</span></strong></p><p><strong><span style="color: rgb(102, 102, 102); font-family: arial, tahoma, 'Microsoft Yahei', 宋体, sans-serif; font-size: 17.1428565979004px; line-height: 32px;">0^1=1,1^3=2;</span></strong></p><p><strong><span style="color: rgb(102, 102, 102); font-family: arial, tahoma, 'Microsoft Yahei', 宋体, sans-serif; font-size: 17.1428565979004px; line-height: 32px;"> x=2;y=3;</span></strong></p><p><strong></strong></p><pre id="recommend-content-581568281" accuse="aContent" class="recommend-text mb-10" style="margin-top: 0px; margin-bottom: 10px; padding: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; white-space: pre-wrap; word-wrap: break-word; color: rgb(51, 51, 51); font-size: 17.1428565979004px; line-height: 24px; background-color: rgb(241, 254, 221);">x^y----->0010----->0011
结果 0001
相同为0,不同为1特性
a=a^b; b=a^b; {此语句为交换a,b值的} a=a^b;例如
a^b^c^c^b^a=a^a^b^b^c^c^c=0^0^0^c=c(a,b.c代表任意整数)
题目代码
#include <stdio.h>
int main()
{
int i,n,s;
while(scanf("%d",&n),n)
{
s=0;
while(n--)
{
scanf("%d",&i);
s^=i;
}
printf("%d\n",s);
}
return 0;
}
;;;;;;;;;;;;;;;
;;;;;;;
<strong>不知道是题目数据的原因还是出题人故意考别人智商,这题如果输出所输入数据的最大值竟然也会AC.</strong>