练习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. 在SpringMVC利用MockMvc进行单元测试

    spring在线文档:https://docs.spring.io/spring/docs/current/javadoc-api/index.html?index-files/index-13.ht ...

  2. [转载]easyui datagrid 时间格化(JS 日期时间本地化显示)

    easyui datagrid 日期时间显示不正常,后台java 类型为 DATE 经过JSON工具一转化传到前台来就是这样,不便 于是想格式化一下, 格式化代码 如下: [javascript] v ...

  3. 怎样快糙猛的开始搞Kaggle比赛

  4. 建立Clojure开发环境-使用IDEA和Leiningen

    OS: Mac OS X 10.10 IDEA 14.0.2 Community Edition 安装Leiningen 按照http://leiningen.org/的指南安装lein 阅读Lein ...

  5. POJ2031Building a Space Station

    http://poj.org/problem?id=2031 题意:你是空间站的一员,太空里有很多球形且体积不一的“小房间”,房间可能相距不近,也可能是接触或者甚至是重叠关系,所有的房间都必须相连,这 ...

  6. ArcGIS学习记录—dbf shp shx sbn sbx mdb adf等类型的文件的解释

    原文地址: ArcGIS问题:dbf shp shx sbn sbx mdb adf等类型的文件的解释 - Silent Dawn的日志 - 网易博客 http://gisman.blog.163.c ...

  7. 安装Hadoop系列 — 新建MapReduce项目

    1.新建MR工程 依次点击 File → New → Ohter…  选择 “Map/Reduce Project”,然后输入项目名称:mrdemo,创建新项目:     2.(这步在以后的开发中可能 ...

  8. dup和dup2函数以及管道的实现

    疑问:管道应该不是这样实现的,因为这要求修改程序的代码 dup和dup2也是两个非常有用的调用,它们的作用都是用来复制一个文件的描述符.它们经常用来重定向进程的stdin.stdout和stderr. ...

  9. Android 签名(6)编译时源码的签名

    1,使用源码中的默认签名 在源码中编译一般都使用默认签名的,在某源码目录中用运行下面命令能看到签名命令. $ mm showcommands Android提供了签名的程序signapk.jar,用法 ...

  10. linux shell 常用基本语法

    转自网络,真正来源不详.... 一. Linux基本命令 1.1.  cp命令 该命令的功能是将给出的文件或目录拷贝到另一文件或目录中,功能十分强大. 语法: cp [选项] 源文件或目录 目标文件或 ...