zoukankan      html  css  js  c++  java
  • Kattis

    Peragrams

    /problems/peragrams/file/statement/en/img-0001.jpg
    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
    ", ans);
    
        }
        return 0;
    }
  • 相关阅读:
    treeview十八般武艺,js选择和绑定权限树
    开源WebOS
    公交车路线查询系统后台数据库设计
    网页信息抓取
    一步一步打造WebIM(3)——性能测试
    WebBrowser介绍——Javascript与C++互操作
    .NET文档生成工具ADB[更新至2.3]
    一步一步打造WebIM(4)——Comet的特殊之处
    在SQL Server中对视图进行增删改
    开源企业即时通讯和在线客服
  • 原文地址:https://www.cnblogs.com/zhien-aa/p/6285871.html
Copyright © 2011-2022 走看看