练习string

最小变换次数下,且字典序最小输出回文串。

 #include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include<deque>
#include<vector>
using namespace std;
const double eps = 1e-;
const double PI = acos(-1.0);
const int maxn=;
string st;
int cnt[maxn];
deque<char> qu;
vector<int> odd; int main()
{
cin>>st;
memset(cnt,,sizeof(cnt[]));
for(int i=; i<st.size(); i++)
{
cnt[st[i]]++;
}
for(int i='a'; i<='z'; i++)
{
if(cnt[i]%)
odd.push_back(i);
}
sort(odd.begin(),odd.end());
int l=;
int r=odd.size()-;
while(l<r)
{
cnt[odd[l]]++;
cnt[odd[r]]--;
l++;
r--;
}
for(int i='a'; i<='z'; i++)
{
if(cnt[i]%)
{
cnt[i]--;
qu.push_back(i);
break;
}
}
for(int i='z'; i>='a'; i--)
{
while(cnt[i])
{
qu.push_back(i);
qu.push_front(i);
cnt[i]-=;
}
}
while(qu.size())
{
cout<<qu.front();
qu.pop_front();
}
cout<<endl;
return ;
}

codeforce 600C - Make Palindrome的更多相关文章

  1. CodeForces - 600C Make Palindrome 贪心

    A string is called palindrome if it reads the same from left to right and from right to left. For ex ...

  2. codeforces 600C Make Palindrome

    要保证变化次数最少就是出现次数为奇数的相互转化,而且对应字母只改变一次.保证字典序小就是字典序大的字母变成字典序小的字母. 长度n为偶数时候,次数为奇数的有偶数个,按照上面说的搞就好了. n为奇数时, ...

  3. Educational Codeforces Round 2

    600A - Extract Numbers    20171106 字符串处理题,稍微注意点细节就能水过 #include<stdlib.h> #include<stdio.h&g ...

  4. Make Palindrome CodeForces - 600C(思维)

    A string is called palindrome if it reads the same from left to right and from right to left. For ex ...

  5. 【Codeforces 600C】Make Palindrome

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 计算出来每个字母出现的次数. 把字典序大的奇数出现次数的字母换成字典序小的奇数出现次数的字母贪心即可. 注意只有一个字母的情况 然后贪心地把字 ...

  6. PALIN - The Next Palindrome 对称的数

    A positive integer is called a palindrome if its representation in the decimal system is the same wh ...

  7. [LeetCode] Longest Palindrome 最长回文串

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  8. [LeetCode] Palindrome Pairs 回文对

    Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that t ...

  9. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

随机推荐

  1. 解决eclipse复制粘贴js代码卡死的问题

    鸣谢:http://blog.csdn.net/zhangzikui/article/details/24805935 ---------------------------------------- ...

  2. ValueError: Attempted relative import in non-package

    执行:python deom/scripts/populate.py ValueError: Attempted relative import in non-package solve:python ...

  3. hdu 4675 GCD of Sequence

    数学题! 从M到1计算,在计算i的时候,算出原序列是i的倍数的个数cnt: 也就是将cnt个数中的cnt-(n-k)个数变掉,n-cnt个数变为i的倍数. 且i的倍数为t=m/i; 则符合的数为:c[ ...

  4. tomcat 禁止某些文件(夹)的访问

    tomcat 禁止某些文件(夹)的访问 <!-- 不允许访问的文件以及文件夹 --> <security-constraint> <display-name>Tom ...

  5. http://doc.okbase.net/congcong68/archive/112508.html

    http://doc.okbase.net/congcong68/archive/112508.html

  6. C语言不是C++的严格子集

    C语言是C++的子集吗?C++是在C语言的基础上扩展而来并包含所有C语言的内容吗? 回复: 从实用角度讲,C++属于C语言的一个超集,基本上兼容ANSI C.但是从编译角度上讲,C语言的有些特性在C+ ...

  7. Shell中调用、引用、包含另一个脚本文件的三种方法

    脚本 first (测试示例1) first#!/bin/bashecho 'your are in first file' 方法一:使用source #!/bin/bashecho 'your ar ...

  8. SPRING IN ACTION 第4版笔记-第九章Securing web applications-003-把用户数据存在数据库

    一. 1.It’s quite common for user data to be stored in a relational database, accessed via JDBC . To c ...

  9. (组合数学3.1.2.1)POJ 2249 Binomial Showdown(排列组合公式的实现)

    /* * POJ_2249.cpp * * Created on: 2013年10月8日 * Author: Administrator */ #include <iostream> #i ...

  10. git bash中带空格的文件夹以及文件的处理

    空格用'\ '表示,输入的时候,是不需要单引号的 total 338drwxr-xr-x 9 Administ Administ 4096 Aug 24 23:53 HDTHelperdrwxr-xr ...