那位说一下我这哪错了啊? 糖果游戏WA80

代码奉上

#include<bits/stdc++.h>
using namespace std;
int n,a[1000005];
long long int A,B;
int main()
{
	freopen("candy.in","r",stdin);
	freopen("candy.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
    reverse(a+1,a+1+n);
	for(int i=1;i<=n;i++)
	{
		if(i%2==1)
			if(a[i]%2==0)
				A+=a[i];
		else
			if(a[i]%2==1)
				B+=a[i];
	}
	if(A>B)cout<<"Alice\n";
	else if(A==B)cout<<"wow\n";
	else cout<<"Bob\n";
	return 0;
}
1 个赞

改成:
(加括号,否则它会识别成其它的意思)

if(i%2==1)
{
    if(a[i]%2==0)
	    A+=a[i];
}
else
{
    if(a[i]%2==1)
	    B+=a[i];
}
1 个赞

好,我试试

1 个赞

谢谢大佬,AC了,解决方案请您笑纳

1 个赞