求解
#include<stdio.h> #include<string.h> char ch[200000]; int main() { scanf("%s", ch); int n = strlen(ch); long long s = 0; for(int i = 0; i < n - 1;i ++) { if(ch[i] != ch[i + 1]) for(int j = i + 1;j < n ;j ++) { if(j == n - 1) { s += (j - i)*(j - i + 1) / 2; i = j; break; } if(ch[j] == ch[j + 1]) { s += (j - i)*(j - i + 1) / 2; i = j; break; } } } printf("%lld", s); return 0; }
求解,只能通过95%