#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string s;
cin>>s;
int sum=0;
for(int i=0;i<n;i++){
sum+=s[i]-'0';//对字符串进行求和
}
for(int i=n;i>=2;i--){//枚举可以分为多少组
if(sum%i==0){
bool ok =true;
int ave=sum/i;
int cur=0;
for(int j=0;j<n;j++){
cur+=s[j]-'0';
if(cur>ave){
ok=false;
break;
}
else if(cur==ave){
cur=0;
}
}
if(ok){
cout<<i<<endl;
return 0;
}
}
}
cout<<-1<<endl;
}
牛客网一题。
最新推荐文章于 2024-09-16 08:54:02 发布