A,80%的代码,WA麻了,求助!!!
#include<bits/stdc++.h> #define int long long using namespace std; int n,m; map<int,int>mp; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin>>t; while(t--) { mp.clear(); cin>>n; int sum=0; for(int i=0;i<n;i++) { int x; cin>>x; sum+=x; mp[x]++; } if(sum%3==0) { string s=""; for(auto [x,y]:mp) { for(int j=0;j<y;j++) s+=to_string(x); } reverse(s.begin(),s.end()); if(s[0]!='0'&&s.size()!=0) cout<<s<<endl; else if(s[0]=='0'&&s.size()!=0) cout<<0<<endl; else cout<<-1<<endl; } if(sum%3==1)//要删掉1 { if(mp.count(1)) mp[1]--; else if(mp.count(4)) mp[4]--; else if(mp.count(7)) mp[7]--; else if(mp[2]>=2) mp[2]-=2; else if(mp[2]>=1&&mp[5]>=1) mp[2]--,mp[5]--; else { cout<<-1<<endl; continue; } string s=""; for(auto [x,y]:mp) { for(int j=0;j<y;j++) s+=to_string(x); } reverse(s.begin(),s.end()); if(s[0]!='0'&&s.size()!=0) cout<<s<<endl; else if(s[0]=='0'&&s.size()!=0) cout<<0<<endl; else cout<<-1<<endl; } if(sum%3==2) { if(mp.count(2)) mp[2]--; else if(mp.count(5)) mp[5]--; else if(mp.count(8)) mp[8]--; else if(mp[1]>=2) mp[1]-=2; else if(mp[1]>=1&&mp[4]>=1) mp[1]--,mp[4]--; else if(mp[4]>=2) mp[4]-=2; else if(mp[1]>=1&&mp[7]>=1) mp[1]--,mp[7]--; else { cout<<-1<<endl; continue; } string s=""; for(auto [x,y]:mp) { for(int j=0;j<y;j++) s+=to_string(x); } reverse(s.begin(),s.end()); if(s[0]!='0'&&s.size()!=0) cout<<s<<endl; else if(s[0]=='0'&&s.size()!=0) cout<<0<<endl; else cout<<-1<<endl; } } return 0; }
}