UVALive 6659 Dromicpalin Substrings 枚举判断

枚举每个位置为起点,然后判断有多少个为奇数的字母,为奇数的<=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
*/


你可能感兴趣的:(uvalive,6659,Dromicpalin,Substrin,枚举判断)