题干:

Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.

Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an oddpositive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!

Input

The first line contains an odd positive integer n — the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.

Output

If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1.

Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.

Examples

Input

527

Output

572

Input

4573

Output

3574

Input

1357997531

Output

-1

题目大意:

给出一个长度小于10^5的奇数,交换其中两位,使其变成一个偶数,若有多种做法输出交换后数字最大的。若不能构造出一个偶数,输出-1。

解题报告:

直接贪心,如果没有偶数就输出-1,否则肯定有解。如果有大于s[len]的偶数那就从前面往后找第一个(因为越靠前越好),否则就从后面往前面找第一个,交换就完事了。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
char s[MAX];
int main()
{cin>>(s+1);int len = strlen(s+1);int flag = 0,ok=0;int tar = s[len]-'0';for(int i = 1; i<=len; i++) {if((s[i]-'0')%2==0) flag = 1;}if(flag == 0) {puts("-1");return 0 ;}for(int i = 1; i<=len; i++) {int cur = s[i]-'0';if(cur%2==0 && tar > cur) {swap(s[i],s[len]);ok=1;break;}}if(ok==1) {printf("%s",s+1);return 0 ;}for(int i = len; i>=1; i--) {int cur = s[i]-'0';if(cur%2==0 /*&& tar<cur*/) {swap(s[i],s[len]);break;}}printf("%s",s+1);return 0 ;}

【CodeForces - 508B】Anton and currency you all know (思维贪心)相关推荐

  1. 【codeforces 508B】Anton and currency you all know

    [题目链接]:http://codeforces.com/contest/508/problem/B [题意] 给你一个奇数; 让你交换一次数字; 使得这个数字变成偶数; 要求偶数要最大; [题解] ...

  2. Codeforces 584E. Anton and Ira (排列好题)

    大致题意: n <= 2000,有一1-n的排列p和s,对pi和pj交换产生的代价是 | i - j | , 问最少需要多少代价使,排列p变成排列s,输出解 思路: 可以先把s映射成1...n的 ...

  3. CodeForces 785C Anton and Fairy Tale 二分

    题意: 有一个谷仓容量为\(n\),谷仓第一天是满的,然后每天都发生这两件事: 往谷仓中放\(m\)个谷子,多出来的忽略掉 第\(i\)天来\(i\)只麻雀,吃掉\(i\)个谷子 求多少天后谷仓会空 ...

  4. CodeForces 785E Anton and Permutation 分块

    题意: 有一个\(1 \sim n\)的排列\(A\),有\(q\)个询问: 交换任意两个元素的位置,求交换之后排列的逆序数 分析: 像这种不太容易用线段树,树状数组维护的可以考虑分块 每\(\sqr ...

  5. Codeforces Round #699 (Div. 2) F - AB Tree(贪心、树上DP)超级清晰,良心题解,看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) F - AB Tree Problem ...

  6. codeforces 465 C. No to Palindromes!(暴力+思维)

    题目链接:http://codeforces.com/contest/465/problem/C 题意:给出一个不存在2个或以上回文子串的字符串,全是由小写字母组成而且字母下表小于p,问刚好比这个字符 ...

  7. Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心

    Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec  Memory Limit: 256 MB Submit: xxx ...

  8. codeforces 872 D. Something with XOR Queries(思维)

    题目链接:http://codeforces.com/contest/872/problem/D 题意:给你一个排列p和对应的位置b也就是说p[b[i]]=i,然后给你最多询问2*n次找出所有的p排列 ...

  9. Codeforces Gym101257F:Islands II(求割点+思维)

    http://codeforces.com/gym/101257/problem/F 题意:给出一个n*m的地图,上面相同数字的代表一个国家,问对于每个国家有多少个国家在它内部(即被包围).例如第一个 ...

最新文章

  1. 王爽著的《汇编语言》第3版笔记
  2. 微服务架构中的雪崩问题产生原因及解决办法
  3. 百万级数据库优化方案
  4. 我的BLOG:阅读目录
  5. Java集合篇:Stack
  6. go操作网页元素_7天用Go动手写/从零实现分布式缓存GeeCache
  7. Visual Source Safe(VSS)使用教程
  8. 吴恩达《机器学习》学习笔记一——初识机器学习
  9. 校园二手交易平台项目总结 ‎2013‎年‎12‎月‎23‎日,‏‎5:57:29
  10. 【python】画图保存为emf
  11. R数据分析:论文中的轨迹的做法,潜增长模型和增长混合模型
  12. Java编程学习-Math类
  13. 智能访客机要注意这些陷阱
  14. mysql从一加到100_MYSQL用存储过程求1到100累加
  15. 友盟APM和bugly全面对比
  16. ccf 202012-3 带配额的文件系统(大模拟)
  17. Android熄屏与亮屏控制
  18. 福昕阅读器给pdf创建目录方法
  19. 液晶显示器测试软件的使用经验分享(资源有下载链接)
  20. bing搜索PubHub发布商指南

热门文章

  1. 电脑功耗监测_应急监测便携式VOC检测仪色谱分析仪原理解析
  2. java knn分类_返回2个或更多最近邻居的KNN算法
  3. 使用Jedis源码生成Jedis.jar
  4. macbook不能进系统 备份数据_不基于备份和表,生产系统数据误删就能完全恢复?!...
  5. 怎么在anaconda上安装python_我是如何用Anaconda来管理Python的
  6. 获取场景中指定类的实例
  7. vs2013编译osg缺少mfc120d.lib
  8. WinCE驱动的动态加载
  9. matlab武汉理工大学数值分析线性函数拟合实验_「首席架构师推荐」数值计算库精选...
  10. python科学计算三剑客_1-python数据分析-数据分析介绍、数据分析三剑客之NumPy