hdu xxxx Peragrams

Peragrams

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 1   Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size:  

Problem Description

Per recently learned about palindromes. Now he wants to tell us about it and also has more awesome scientific news to share with us.
“A palindrome is a word that is the same no matter whether you read it backward or forward”, Per recently said in an interview. He continued: “For example, ‘add’ is not a palindrome, because reading it backwards gives ‘dda’ and it’s actually not the same thing, you see.
However, if we reorder the letters of the word, we can actually get a palindrome. Hence, we say that ‘add’ is a Peragram, because it is an anagram of a palindrome”.
Per gives us a more formal definition of Peragrams: “Like I said, if a word is an anagram of at least one palindrome, we call it a Peragram. And recall that an anagram of a word w contains exactly the same letters as w, possibly in a different order.”

Given a string, find the minimum number of letters you have to remove from it, so that the string becomes a Peragram. 

Input

Multiple cases. Each case consists of a string on a single line. The string will contain at least 1 and at most 1000 characters. The string will only contain lowercase letters ‘a’-‘z’.

Output

For each case, the output should consist of a single integer on a single line, the minimum number of characters that have to be removed from the string to make it a Peragram.

Sample Input

abc 
aab

Sample Output

2
0
 
 
回文串的性质啦.
#include <stdio.h>
#include <string.h>

#define MAX 1005

char str[MAX];
int c[26];
int o, e;

int main() {
	int i;

	while (scanf("%s", str) != EOF) {
		memset(c, 0, sizeof(c));
		for (i = 0; str[i] != '\0'; i++) {
			c[str[i] - 'a']++;
		}

		o = e = 0;
		for (i = 0; i < 26; i++) {
			if (c[i] % 2) {
				e++;
			}
		}

		if (e == 0) {
			printf("0\n");
		} else {
			printf("%d\n", e - 1);
		}
	}

	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值