Kattis - Peragrams
Peragrams

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的更多相关文章
- It's a Mod, Mod, Mod, Mod World Kattis - itsamodmodmodmodworld (等差数列求和取模)
题目链接: D - It's a Mod, Mod, Mod, Mod World Kattis - itsamodmodmodmodworld 具体的每个参数的代表什么直接看题面就好了. AC代码: ...
- A - Piece of Cake Kattis - pieceofcake (数学)
题目链接: A - Piece of Cake Kattis - pieceofcake 题目大意:给你一个多边形,然后给你这个多边形的每个点的坐标,让你从这个n个点中选出k个点,问这个k个点形成的面 ...
- Subsequences in Substrings Kattis - subsequencesinsubstrings (暴力)
题目链接: Subsequences in Substrings Kattis - subsequencesinsubstrings 题目大意:给你字符串s和t.然后让你在s的所有连续子串中,找出这些 ...
- G - Intersecting Rectangles Kattis - intersectingrectangles (扫描线)(判断多个矩形相交)
题目链接: G - Intersecting Rectangles Kattis - intersectingrectangles 题目大意:给你n个矩形,每一个矩形给你这个矩形的左下角的坐标和右上角 ...
- E - Emptying the Baltic Kattis - emptyingbaltic (dijkstra堆优化)
题目链接: E - Emptying the Baltic Kattis - emptyingbaltic 题目大意:n*m的地图, 每个格子有一个海拔高度, 当海拔<0的时候有水. 现在在(x ...
- G - Galactic Collegiate Programming Contest Kattis - gcpc (set使用)
题目链接: G - Galactic Collegiate Programming Contest Kattis - gcpc 题目大意:当前有n个人,一共有m次提交记录,每一次的提交包括两个数,st ...
- Kattis - virus【字符串】
Kattis - virus[字符串] 题意 有一个正常的DNA序列,然后被病毒破坏.病毒可以植入一段DNA序列,这段插入DNA序列是可以删除正常DNA序列中的一个连续片段的. 简单来说就是,给你一段 ...
- Kattis - bank 【简单DP】
Kattis - bank [简单DP] Description Oliver is a manager of a bank near KTH and wants to close soon. The ...
- City Destruction Kattis - city dp
/** 题目:City Destruction Kattis - city 链接:https://vjudge.net/problem/Kattis-city 题意:有n个怪兽,排成一行.每个怪兽有一 ...
随机推荐
- DynamicResource与StaticResource的区别
原文:DynamicResource与StaticResource的区别 2008-06-20 12:16:12 静态资源在第一次编译后即确定其对象或值,之后不能对其进行修改.动态资源则是在运行时决定 ...
- NYOJ 58 步数最少 【BFS】
意甲冠军:不解释. 策略:如果: 这个问题也可以用深宽搜索搜索中使用.我曾经写过,使用深层搜索.最近的学校范围内的搜索,拿这个问题来试试你的手. 代码: #include<stdio.h> ...
- 【转】Android实现推送方式解决方案
本文介绍在Android中实现推送方式的基础知识及相关解决方案.推送功能在手机开发中应用的场景是越来起来了,不说别的,就我们手机上的新闻客户端就时不j时的推送过来新的消息,很方便的阅读最新的新闻信息. ...
- .NET开发面向对象1
ASP.NET开发,从二层至三层,至面向对象 昨天Insus.NET有写了一篇博文<WEB控件没有什么所谓好不好,而是用得好不好>http://www.cnblogs.com/insus/ ...
- 轻量级IOC框架:Ninject
Ninject 学习杂记 - liucy 时间2014-03-08 00:26:00 博客园-所有随笔区原文 http://www.cnblogs.com/liucy1898/p/3587455.h ...
- [置顶] 网页提交方式post和get的区别和联系
都知道GET一般用于获取/查询资源信息,而POST一般用于更新资源信息.但具体区别呢?可以互换吗? 主要区别有:1传输数据的方式不同,2传输的数据多少不同,3传输数据的安全性不同4,后台获取数据的方式 ...
- SQLSERVER数据库学习总结七(视图,索引)
--视图的主意点:不能和表的名称相同,如果某一列为函数,表达式,常量或者与来自多张表的列名相同,必须为列定义名称,不能在试图上创建索引 if exists(select 1 from sys.syso ...
- uva 305 Joseph
点击打开链接uva 305 思路: 数学+打表 分析: 1 传统的约瑟夫问题是给定n个人和m,每次数m次把当前这个人踢出局,问最后留下的一个人的编号 2 这一题是前k个人是好人,后面k个是坏人.现在要 ...
- Hashtable Dictionary List
Hashtable Dictionary List 谁效率更高 一 前言 很少接触HashTable晚上回来简单看了看,然后做一些增加和移除的操作,就想和List 与 Dictionary比较下存 ...
- 广告基本知识-ROI分解
任何一个在线广告系统,都面临ROI的问题,对于Invest,我们先不考虑,因为对于流量有多种方式可以买回,也无法优化(当然在RTB的时候是可以优化的).Return是主要优化的方向,Return=点击 ...