UVALive 6659 Dromicpalin Substrings 枚举判断

来源:互联网 发布:淘宝图片上传大小 编辑:程序博客网 时间:2024/04/29 11:53

枚举每个位置为起点,然后判断有多少个为奇数的字母,为奇数的<=1这个区间可以变成回文串。ans++


#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>using namespace std;int num[200];char word[2000];int main(){    int n,tt=1;    scanf("%d",&n);    while(n--){        int ans = 0;        scanf("%s",word);        int len = strlen(word);        for(int i = 0;i < len; i++){            memset(num,0,sizeof(num));            int res = 0;            for(int j = i;j < len; j++){                num[word[j]]++;                if(num[word[j]] & 1) res++;                else res--;                if(res <= 1) ans++;            }        }        printf("Case %d: %d\n",tt++,ans);    }    return 0;}/*4 acmicpc*/


0 0