为什么2 3 1 4的情况会错呢 萌新求调
查看原帖
为什么2 3 1 4的情况会错呢 萌新求调
1228133
Ethan_GJS楼主2024/12/1 11:27
#include<iostream>
using namespace std;
int a[10005];
int main(){
	int t,n;
	cin>>t;
	for(int i=1;i<=t;i++){
		int sum=0,ans=0;
		double pd=false;
		cin>>n;
		for(int j=1;j<=n;j++){
			cin>>a[i];
			sum+=a[i];
		}
		for(int k=1;k<=n;k++){
			ans+=a[k];
			if(sum==ans*2){
				cout<<"Yes"<<endl;
				pd=true;        
				break;            
			}
		}
		if(pd==false) cout<<"No"<<endl;
	}
	return 0;
}
2024/12/1 11:27
加载中...