s^=a[i];什么意思 C语言#includeint a[101];int main(){int m,s,i;while(scanf("%d",&m) && m){s = 0;for(i = 0;i < m;i++){scanf("%d",&(a[i]));s ^= a[i];}if(s == 0)printf("0\n");else{int cnt = 0;for(i = 0;i < m;i++){s ^= a[i]; //选一堆if (a[i] > s)

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 14:49:57

s^=a[i];什么意思 C语言#includeint a[101];int main(){int m,s,i;while(scanf("%d",&m) && m){s = 0;for(i = 0;i < m;i++){scanf("%d",&(a[i]));s ^= a[i];}if(s == 0)printf("0\n");else{int cnt = 0;for(i = 0;i < m;i++){s ^= a[i]; //选一堆if (a[i] > s)
s^=a[i];什么意思 C语言
#include
int a[101];
int main()
{
int m,s,i;
while(scanf("%d",&m) && m)
{
s = 0;
for(i = 0;i < m;i++)
{
scanf("%d",&(a[i]));
s ^= a[i];
}
if(s == 0)
printf("0\n");
else
{
int cnt = 0;
for(i = 0;i < m;i++)
{
s ^= a[i]; //选一堆
if (a[i] > s) //如果剩余的堆异或得到的值 小于 这一堆 ,才能赢.
cnt++;
s ^= a[i]; //重新把这堆加进去,准备选下一堆
}
printf("%d\n",cnt);
}
}
return 0;
}
这就是代码,输入3
5 7 9
返回1;输入0时结束;
s ^= 如果是s=s^a[i];
输入5时应该是 s=0^5=0才对啊,为什么是s=5?

s^=a[i];什么意思 C语言#includeint a[101];int main(){int m,s,i;while(scanf("%d",&m) && m){s = 0;for(i = 0;i < m;i++){scanf("%d",&(a[i]));s ^= a[i];}if(s == 0)printf("0\n");else{int cnt = 0;for(i = 0;i < m;i++){s ^= a[i]; //选一堆if (a[i] > s)
异或运算:同则0,异则1
0 = 0 0 0 0
5 = 0 1 0 1
--------------
0 1 0 1 = 5