练习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. 闭包小demo

    var a = (function(){ var c= 0; return function(){ return ++c; } }()); var g = a(); console.log(g); v ...

  2. [转载]C#缓存absoluteExpiration、slidingExpiration两个参数的疑惑

    看了很多资料终于搞明白cache中absoluteExpiration,slidingExpiration这两个参数的含义. absoluteExpiration:用于设置绝对过期时间,它表示只要时间 ...

  3. 破解之API断点法

    上回给大家做的破解教程,地址是http://www.52pojie.net/thread-52719-1-1.html,用的是“调用堆栈”方法.今天给新手提供另一种方法“API函数断点”,这种方法要求 ...

  4. Jmeter 使用实践 - 接口 diff 测试

    大多数人都使用 Jmeter 做过性能测试,但是在使用的过程中你会发现,它不仅可以做性能测试和功能测试,还能够满足基本的接口测试需求. 相比其他工具,Jmeter 入门门槛较低,安装也比较方便,根据自 ...

  5. Debugging with GDB 用GDB调试多线程程序

    Debugging with GDB http://www.delorie.com/gnu/docs/gdb/gdb_25.html GDB调试多线程程序总结 一直对GDB多线程调试接触不多,最近因为 ...

  6. codeforces #310 div1 E

    算得上是比较水的E题了吧,自己想了想写了写居然1A了 对于这道题,我们很容易想到对于原图的一个边双,定向后任意两点间一定可达 那么我们可以求出原图的边双并将每个边双缩成一个点 那么原图就变成了无环的无 ...

  7. P132、面试题21:包含min函数的栈

    实现思路:们需要一个辅助栈.每次push一个新元素的时候,同时将最小元素(或最小元素的位置.考虑到栈元素的类型可能是复杂的数据结构,用最小元素的位置将能减少空间消耗)push到辅助栈中:每次pop一个 ...

  8. python学习笔记四--元组

    一.元组: 1. 不可变更的列表 2. 从语法上,她们是编写在小括号里,不是方括号里,列表是编写在方括号里的 3. 圆括号也同时用于表达式,如果想说明这是一个元组,不是表达式,可以在value后,关闭 ...

  9. linux切换用户

    当前使用root账户 [root@localhost chucklu]# cd[root@localhost ~]# pwd/root 切换到普通账户 [root@localhost ~]# su c ...

  10. 普通方式 分页【NOT IN】和【>】效率大PK 千万级别数据测试结果

    首现创建一张表,然后插入1000+万条数据,接下来进行测试. use TTgoif exists (select * from sysobjects where name='Tonge')drop t ...