HDU - 6480
http://acm.hdu.edu.cn/showproblem.php?pid=6480
#include<iostream> using namespace std; typedef long long ll; int main() { int t; cin>>t; while(t--) { string s; cin>>s; ll ans=0, cnt=1; for(int i=0; i<s.size();) { if(s[i]==s[i+1]) { cnt++; i++; } else { ans+=((cnt+1)*cnt)/2; cnt=1; i++; } } cout<<ans<<endl; } }

浙公网安备 33010602011771号