标签:fine har bsp sum main strlen define ace nbsp
思路:
前缀和;
来,上代码:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 1000005 int n,sum[maxn]; char ch[maxn]; int main() { gets(ch),n=strlen(ch); for(int i=0;i<n;i++) sum[i]=sum[i==0?0:i-1]+ch[i]-‘0‘; if(sum[n-1]==0) { cout<<0; return 0; } for(int i=1;i<n;i++) { if(i-sum[i-1]==sum[n-1]-sum[i-1]) { cout<<i; return 0; } } if(sum[n-1]==n) { cout<<n; return 0; } cout<<-1; return 0; }
标签:fine har bsp sum main strlen define ace nbsp
原文地址:http://www.cnblogs.com/IUUUUUUUskyyy/p/6757550.html