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个怪兽,排成一行.每个怪兽有一 ...
随机推荐
- 2014由于在myeclipse5.5.1许可证
点击假设Myeclipse负载项目server该图标不响应.这是MyEclipse过期,这也是一年许可: subscriber: axin Serial:nLR8ZC-855575-69517252 ...
- mysql 基础之CURD
原文:mysql 基础之CURD 增删改查基本语法学习 增: insert Insert 3问: 1: 插入哪张表? 2: 插入哪几列? 3: 这几列分别插入什么值? Insert into Tabl ...
- 如何防范CC攻击
服务器如何防范CC攻击CC攻击是DDOS(分布式拒绝服务)的一种,相比其它的DDOS攻击CC似乎更有技术含量一些.这种攻击你见不到虚假IP,见不到特别大的异常流量,但造成服务器无法进行正常连接,听说一 ...
- MY WAY程序(十八) 团队开发
1.通信知识 要了解的强哥的移动通信先验知识布局.我和另外一个毕业生有自己的学习,但我真的没有认真看.了解了一下,其余大部分时间在搞nodejs.另外一个应届毕业生则是按着一本电子书 ...
- Content Negotiation(内容协商)
Asp.Net Web API 2第十四课——Content Negotiation(内容协商) 前言 阅读本文之前,您也可以到Asp.Net Web API 2 系列导航进行查看 http:// ...
- ASP.NET MVC中使用Unity进行依赖注入的三种方式
在ASP.NET MVC中使用Unity进行依赖注入的三种方式 2013-12-15 21:07 by 小白哥哥, 146 阅读, 0 评论, 收藏, 编辑 在ASP.NET MVC4中,为了在解开C ...
- Visual Stuido也有非常多的快捷键
最近看到很多同事用 VI 来开发Ruby,Python脚本. 编辑代码全部用的是快捷键,效率很高. 其实Visual Stuido也有非常多的快捷键,熟练运用后,能大大提高工作效率. 本文介绍一些最常 ...
- 【转】在iOS开发中使用FMDB
本文转载自:唐巧的博客 在iOS开发中使用FMDB APR 22ND, 2012 前言 SQLite (http://www.sqlite.org/docs.html) 是一个轻量级的关系数据库.iO ...
- 反向代理-- WEB服务的加速器[转]
昨天j.L问我http cache怎么设置,当时脑子有点糊涂,一时没想到其实他问的就是反向代理如何设置. 首发:PHP CUP xiaobao 什么是反向代理?反 向代理就是代理服务器(如ISA.Sq ...
- 支持异步同步的分布式CommandBus MSMQ实现
支持异步同步的分布式CommandBus MSMQ实现 先上一张本文所描述的适用场景图 分布式场景,共3台server: 前端Server Order App Server Warehouse App ...