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

【题意】

题意

【题解】

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

【代码】

#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. ssh验证和端口转发

    ssh 服务登录验证 ssh 服务登录验证方式: 用户/ 口令 基于密钥 基于用户和口令登录验证 客户端发起ssh请求,服务器会把自己的公钥发送给用户 用户会根据服务器发来的公钥对密码进行加密 加密后 ...

  2. bzoj 1492: [NOI2007]货币兑换Cash【贪心+斜率优化dp+cdq】

    参考:http://www.cnblogs.com/lidaxin/p/5240220.html 虽然splay会方便很多,但是懒得写,于是写了cdq 首先要想到贪心的思路,因为如果在某天买入是能得到 ...

  3. hdu 模拟 贪心 4550

    卡片游戏 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Su ...

  4. 使用Redis存储Nginx+Tomcat负载均衡集群的Session

    配置Tomcat的session共享可以有三种解决方案: 第一种是以负载均衡服务器本身提供的session共享策略,每种服务期的配置是不一样的并且nginx本身是没有的. 第二种是利用web容器本身的 ...

  5. Bryce1010 Acm模板

    目录 STL标准模板库 STL简介 STL pair STL set STL vector STL string STL stack STL queue STL map upper_bound和low ...

  6. css为tbody或者li奇数偶数行样式

    <style> table tbody tr:nth-child(odd){ background:#fff; } table tbody tr:nth-child(even){ back ...

  7. [转]深入ASP.NET MVC之二:路由模块如何工作

    本文转自:http://www.cnblogs.com/yinzixin/archive/2012/11/05/2754483.html 摘要: 上文分析了UrlRouting模块何时会被触发,本文重 ...

  8. Python的I/O操作

    1.读取键盘输入 msg = raw_input("Please enter :") print "you input ",msg #可接受Python表达式作 ...

  9. windows多线程应用编程注意事项

    1,资源争用保护 对于文件操作.界面资源.GDI操作等一般由主线程完成的任务,要加以顺序化处理(serialization),即一个资源一次只能由一个线程访问,多个线程同时访问将导致错误. 方法一般可 ...

  10. iOS设计模式——Category和 Extension

    什么是Category Category模式用于向已经存在的类添加方法从而达到扩展已有类的目的,在很多情形下Category也是比创建子类更优的选择.新添加的方法同样也会被被扩展的类的所有子类自动继承 ...