【链接】 我是链接,点我呀:)

【题意】

题意

【题解】

计算出来每个字母出现的次数。
把字典序大的奇数出现次数的字母换成字典序小的奇数出现次数的字母贪心即可。
注意只有一个字母的情况
然后贪心地把字典序小的字母放在前面就好

【代码】

#include <bits/stdc++.h>
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define ll long long
using namespace std; const int N = 2e5; string s;
char ans[N+10];
int cnt[30]; int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> s;
rep1(i,0,(int)s.size()-1) cnt[s[i]-'a'+1]++;
for (int i = 1;i <= 26;i++)
if (cnt[i]&1){
for (int j = 26;j >= i+1;j--)
if (cnt[j]&1){
cnt[i]++;
cnt[j]--;
break;
}
}
rep1(i,1,(int)s.size()/2){
for (int j = 1;j <= 26;j++){
if ( (cnt[j]>0 && cnt[j]%2==0) || (cnt[j]>2) ){
ans[i] = (char)(j+'a'-1);
ans[(int)s.size()-i+1] = ans[i];
cnt[j]-=2;
break;
}
}
}
if ((int)s.size()%2==1){
for (int j = 1;j <= 26;j++)
if (cnt[j]%2==1)
ans[(int)s.size()/2+1] = (char)(j+'a'-1);
}
for (int i = 1;i <= (int)s.size();i++){
cout<<ans[i];
}
return 0;
}

【Codeforces 600C】Make Palindrome的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 798A】Mike and palindrome

    [题目链接]:http://codeforces.com/contest/798/problem/A [题意] 让你严格改变一个字符,使得改变后的字符串为一个回文串; 让你输出可不可能; [题解] 直 ...

  3. 【19.77%】【codeforces 570D】Tree Requests

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【34.88%】【codeforces 569C】Primes or Palindromes?

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【25.64%】【codeforces 570E】Pig and Palindromes

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【44.19%】【codeforces 608D】Zuma

    time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

  7. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  8. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  9. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

随机推荐

  1. 全分布式的Hadoop虚拟机安装

    在集群环境下装机.配置.运行的全过程,梳理总结到本文中. 第一部分:环境规划 •用户 hadoop 密码 hadoop •机器 机器名称 IP地址 Master.Hadoop 192.168.1.10 ...

  2. MyBatis基本应用

    框架的概念: 框架(Framework)是一个提供了可重用的公共结构的半成品. 数据持久化: 数据持久化是将内存中的数据模型转换为存储模型,以及将存储模型转换为内存中的数据模型的统称. ORM(Obj ...

  3. ACM_递推题目系列之三放苹果(递推dp)

    递推题目系列之三放苹果 Time Limit: 2000/1000ms (Java/Others) Problem Description: 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放 ...

  4. windows 定时任务 设置 安全事项

    windows 定时任务 设置 安全事项 1.如果是oaadmin/administrator 创建oracle 数据库. 安全选项如下: 1.只是在用户登录时候运行. sample: data ho ...

  5. [转]ASP.NET MVC HtmlHelper扩展之Calendar日期时间选择

    本文转自:http://blog.bossma.cn/asp_net_mvc/asp-net-mvc-htmlhelper-calendar-datetime-select/ 这里我们扩展HtmlHe ...

  6. 小白的python之路 序

    计算机专科毕业,.net开发已有8年有余,中途断断续续,似懂非懂,积累了一些经验知识,但是不求甚解,属于那种一瓶不满半瓶子晃荡,这么一个状态. 主要从事web开发,涉及一些前端jq等,还有接口开发,搜 ...

  7. 致创业者:APP已死 服务永生

    前几日,有位创业者和我讲他在带领团队做一个将爱踢球的人集中在一起的App,我告诉他你的创业方向错了.原因在于你的目的是要为爱踢球的人提供服务,而你现在却在竭尽全力的做App,你应该做的是设计你为爱踢球 ...

  8. SpringMvc下的文件上传

    首先是springmvc.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=&q ...

  9. 本地编译全志R系列的步骤7(Ubuntu 17.04非长期支持版本)

    本地编译全志R系列的步骤7(Ubuntu 17.04非长期支持版本) 2017/6/29 13:49 0.获取全志R系列的Android源码包: 请通过渠道/代理商/方案公司获取全志R系列的Andro ...

  10. Tcl之Read files for synthesis

    The following file is to read all design files into syntehsis tool automatically, like Cadence RTL C ...