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个怪兽,排成一行.每个怪兽有一 ...
随机推荐
- navigator获取参数
<script type="text/javascript" language="javascript"> document.write(" ...
- 使用Repository模式构建数据库访问层
使用Repository模式构建数据库访问层 使用ASP.NET Web Api构建基于REST风格的服务实战系列教程[二]——使用Repository模式构建数据库访问层 系列导航地址http:// ...
- [Usaco2008 Feb]Eating Together麻烦的聚餐[最长不下降子序列]
Description 为了避免餐厅过分拥挤,FJ要求奶牛们分3批就餐.每天晚饭前,奶牛们都会在餐厅前排队入内,按FJ的设想所有第3批就餐的奶牛排在队尾,队伍的前端由设定为第1批就餐的奶牛占据,中间的 ...
- 用Haproxy给MySQL做负载均衡
1.安装 # wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.24.tar.gz # tar zcvf haproxy-1.4.24.t ...
- 计算image 积分图
// testopencv.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <opencv2\opencv.hpp& ...
- [Usaco2008 Nov]Guarding the Farm 保卫牧场[DFS]
Description The farm has many hills upon which Farmer John would like to place guards to ensure the ...
- ASP.NET虚拟路径小结
一.虚拟路径的概念 “虚拟路径”是指请求 URL 中跟在服务器标识符后面的部分举例. 如绝对路径:http://www.mysite.com/MyApp/Default.aspx,其对应的虚拟路径为: ...
- 用Python实现gmail邮箱服务,实现两个邮箱之间的绑定(下)
一.我的需求 我希望做成具有以下功能的软件:1. 间隔一段时间登录我的邮箱查看是否有未读邮件 如果不断的运行查看是否有新邮件确实没多大必要. 另外如果这个客户端登录我的邮箱,那么我可能就不能用浏览器登 ...
- JavaScript之创建对象
不定义JQuery插件,不要说会JQuery 一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页上写一写$("#"),$("."),写了几年就对 ...
- CMStepCounter Class Refernce
CMStepCounter Class Refernce https://developer.apple.com/library/ios/documentation/CoreMotion/Refere ...