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

题意

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

思路

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

代码

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

Kattis - Peragrams的更多相关文章

  1. It's a Mod, Mod, Mod, Mod World Kattis - itsamodmodmodmodworld (等差数列求和取模)

    题目链接: D - It's a Mod, Mod, Mod, Mod World Kattis - itsamodmodmodmodworld 具体的每个参数的代表什么直接看题面就好了. AC代码: ...

  2. A - Piece of Cake Kattis - pieceofcake (数学)

    题目链接: A - Piece of Cake Kattis - pieceofcake 题目大意:给你一个多边形,然后给你这个多边形的每个点的坐标,让你从这个n个点中选出k个点,问这个k个点形成的面 ...

  3. Subsequences in Substrings Kattis - subsequencesinsubstrings (暴力)

    题目链接: Subsequences in Substrings Kattis - subsequencesinsubstrings 题目大意:给你字符串s和t.然后让你在s的所有连续子串中,找出这些 ...

  4. G - Intersecting Rectangles Kattis - intersectingrectangles (扫描线)(判断多个矩形相交)

    题目链接: G - Intersecting Rectangles Kattis - intersectingrectangles 题目大意:给你n个矩形,每一个矩形给你这个矩形的左下角的坐标和右上角 ...

  5. E - Emptying the Baltic Kattis - emptyingbaltic (dijkstra堆优化)

    题目链接: E - Emptying the Baltic Kattis - emptyingbaltic 题目大意:n*m的地图, 每个格子有一个海拔高度, 当海拔<0的时候有水. 现在在(x ...

  6. G - Galactic Collegiate Programming Contest Kattis - gcpc (set使用)

    题目链接: G - Galactic Collegiate Programming Contest Kattis - gcpc 题目大意:当前有n个人,一共有m次提交记录,每一次的提交包括两个数,st ...

  7. Kattis - virus【字符串】

    Kattis - virus[字符串] 题意 有一个正常的DNA序列,然后被病毒破坏.病毒可以植入一段DNA序列,这段插入DNA序列是可以删除正常DNA序列中的一个连续片段的. 简单来说就是,给你一段 ...

  8. Kattis - bank 【简单DP】

    Kattis - bank [简单DP] Description Oliver is a manager of a bank near KTH and wants to close soon. The ...

  9. City Destruction Kattis - city dp

    /** 题目:City Destruction Kattis - city 链接:https://vjudge.net/problem/Kattis-city 题意:有n个怪兽,排成一行.每个怪兽有一 ...

随机推荐

  1. WinForm窗体淡入效果界面的简单实现方法

    WinForm窗体淡入效果主要使用到控件的Opacity属性 首先在WinForm窗体中拖入一个Timer控件,然后再Timer控件的Tick事件添加如下代码: private void timer1 ...

  2. C注意,使用的语言字符串

    转载请注明出处! 在C语言没有具体的字符串数据类型,字符串的字符串常量和字符数组的形式. 实际上该字符串是零个或更多字符的字符串.并在整个位模式0NUL字节结束.因此,字符串所包括的字符内部不能出现N ...

  3. vs10创建sqlclr部署失败

    将项目解决方案改为3.5,调试OK:

  4. Jetbrains 系列神器

    PRODUCTS IntelliJ IDEA ReSharper WebStorm PhpStorm PyCharm RubyMine AppCode YouTrack TeamCity dotTra ...

  5. Working with Entity Relations in OData

    Working with Entity Relations in OData 前言 阅读本文之前,您也可以到Asp.Net Web API 2 系列导航进行查看 http://www.cnblogs. ...

  6. 【IOS开发】《多线程编程指南》笔记

    线程是单个应用中可以并发执行多个代码路径的多种技术之一.虽然更新的技术如操作对象(Operation)和Grand Central Dispatch(GCD),提供一个等价现代化和高效的基础设施来实现 ...

  7. fiddle2 代理HTTPS请求无效?解决方法。

    fiddle2: 捕获的https请求结尾跟着443,是因为没有开启HTTPS捕获. 解决方案,开启HTTPS捕获:         然后你就看到能正常捕获HTTPS请求了:    

  8. new关键字

    Javascript的实例化与继承:请停止使用new关键字   本文同时也发表在我另一篇独立博客 <Javascript的实例化与继承:请停止使用new关键字>(管理员请注意!这两个都是我 ...

  9. 我的TDD实践---SVN架设篇

    我的TDD实践---SVN架设篇 “我的TDD实践”系列之SVN架设 写在前面: 我的TDD实践这几篇文章主要是围绕测试驱动开发所展开的,其中涵盖了一小部分测试理论,更多的则是关注工具的使用及环境的搭 ...

  10. elasticsearch data importing

    ElasticSearch stores each piece of data in a document. That's what I need. Using the bulk API. Trans ...