Uestc_how many good substrings cdoj 1026

Source: Internet
Author: User

IcerainLikes strings very much. Especially the strings only consist 0 1 of and, she call them easy strings. One day, she's so boring this she want to the find how many good substrings in a easy string?

A good substring is a substring which can are a palindrome string after your change any of the characters ' positions (you can Do the operation any times). For Example,  is a good substring of 1001 , beacuse can change it to be < Span class= "Mathjax_preview" >010 , which is a palindrome string.

Input

The first line is the number of test cases. (No more than )

Each test case has a line containing one string with only consist of and 0 1 . The length of the string is no greater than 100000.

Output

For each test case, output one line contains the number of good substrings.

Sample Input and output
Sample Input Sample Output
20101101
211

Problem Solving Report

Prefix DP ... Thank Ching for your guidance.

1#include <iostream>2#include <cstring>3#include <algorithm>4 using namespacestd;5 Const intMAXN = 1e5 +5;6 intdp[4];7 CharBUFFER[MAXN];8 9 intMainintargcChar*argv[])Ten { One   intCase ; Ascanf"%d",&Case ); -    while(case--) -    { thescanf"%s", buffer); -          intLen =strlen (buffer); -          Long LongAns =0; -Memset (DP,0,sizeof(DP)); +           for(inti =1; I <= Len; ++i) -           { +                 intFlag =0; A                 if(buffer[i-1] =='1') at                  { -Swap (dp[0],dp[1]); -Swap (dp[2],dp[3]); -Flag =1; -            } -           Else  in            { -Swap (dp[0],dp[3]); toSwap (dp[1],dp[2]); +            } -           if(flag) thedp[2] ++ ; *           Else $dp[0] ++ ;Panax NotoginsengAns + = (dp[0] + dp[2] + dp[3]); -        } thecout << ans <<Endl; +    } A   return 0; the}

Uestc_how many good substrings cdoj 1026

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.