首页 > 其他 > 详细

Kattis - Peragrams

时间:2017-01-14 19:03:43      阅读:254      评论:0      收藏:0      [点我收藏+]

Peragrams

技术分享
Photo by Ross Beresford

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 ww contains exactly the same letters as ww, possibly in a different order.”

Task

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

Input

Input consists of a string on a single line. The string will contain at least 11 and at most 10001000 characters. The string will only contain lowercase letters a-z.

Output

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 1Sample Output 1
abc
2
Sample Input 2Sample Output 2
aab
0

题意

问给出的字符串需要删除多少个字母后才能组成回文串

思路

相同字母个数是偶数的话才能构成回文,奇数字母只能有一个,所以只需要统计每个字母的个数,然后,答案就是个数为奇数的字母数-1

代码

#include<bits/stdc++.h>
int vis[30];
char aa[1005];
int main() {
    while (~scanf("%s", aa))
    {
        memset(vis, 0, sizeof(vis));
        int len = strlen(aa);
        for (int i = 0; i < len; i++)
        {
            vis[aa[i] - a]++;
        }
        int ans = 0;
        for (int i = 0; i < 26; i++)
        {
            if (vis[i] % 2)
            {
                ans++;
            }
        }
        if (ans) ans--;
        printf("%d\n", ans);

    }
    return 0;
}

 

 

Kattis - Peragrams

原文:http://www.cnblogs.com/zhien-aa/p/6285871.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!