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

题解:找小于末尾奇数的第一个偶数,如果没有,选择最后一个偶数,没偶数则输出-1

通过这道题,我明白了strlen的时间复杂度为O(n),如果放循环内,相当于时间复杂度为O(len*n)就容易超时,所以要提前接出放外面

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath> using namespace std; int main() { char s[100005];
scanf("%s",s);
//sort(s,s+strlen(s));
int k=-1;
int flag=0;
int minn;
for(int t=0; t<strlen(s); t++) {
if(s[t]-'0'<s[strlen(s)-1]-'0'&&(s[t]-'0')%2==0) {
k=t;
// flag=1;
break;
}
}
//cout<<k<<endl;
for(int t=0; t<strlen(s); t++) {
if((s[t]-'0')%2==0) {
minn=t;
flag=1;
}
}
//cout<<minn<<endl;
if(flag==0) {
cout<<"-1"<<endl;
return 0;
} else {
for(int t=0; t<strlen(s); t++) {
if(t==k) {
swap(s[k],s[strlen(s)-1]);
break;
}
if(k==-1) {
swap(s[minn],s[strlen(s)-1]);
break; } }
//printf("%s",s);//也可通过
int len=strlen(s);
for(int t=0; t<len; t++) {
printf("%c",s[t]);
}
} return 0;
}

CodeForces - 508B-Anton and currency you all know的更多相关文章

  1. 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know

    题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...

  2. Codeforces Round #288 (Div. 2) B. Anton and currency you all know 贪心

    B. Anton and currency you all know time limit per test 0.5 seconds memory limit per test 256 megabyt ...

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

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

  4. Codeforces 734E. Anton and Tree 搜索

    E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard ...

  5. Codeforces 593B Anton and Lines

    LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...

  6. Codeforces Round #313 A Currency System in Geraldion

    A  Currency System in Geraldion Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64 ...

  7. Codeforces 734F Anton and School(位运算)

    [题目链接] http://codeforces.com/problemset/problem/734/F [题目大意] 给出数列b和数列c,求数列a,如果不存在则输出-1 [题解] 我们发现: bi ...

  8. [刷题]Codeforces 785D - Anton and School - 2

    Description As you probably know, Anton goes to school. One of the school subjects that Anton studie ...

  9. Codeforces 785D - Anton and School - 2 - [范德蒙德恒等式][快速幂+逆元]

    题目链接:https://codeforces.com/problemset/problem/785/D 题解: 首先很好想的,如果我们预处理出每个 "(" 的左边还有 $x$ 个 ...

  10. Codeforces 584E - Anton and Ira - [贪心]

    题目链接:https://codeforces.com/contest/584/problem/E 题意: 给两个 $1 \sim n$ 的排列 $p,s$,交换 $p_i,p_j$ 两个元素需要花费 ...

随机推荐

  1. 尚学堂xml学习笔记

    1.打开eclipse,文件-新建java project,输入文件的名字,比如输入20181112. 2.对着src右键,选择new-file,输入文件名字,比如:book.xml. 3.开始写.x ...

  2. 虚拟参考站(VRS)

    来源:https://www.sohu.com/a/149415053_391994 一.高精度定位 VRS是虚拟参考站(Virtual Reference Station)的简称.这项技术是CORS ...

  3. 改变Ecplise项目窗口字体样式

    Eclipse\plugins\org.eclipse.ui.themes_1.1.1.v20151026-1355\css e4-dark_win.css CTabFolder Tree, CTab ...

  4. L85

    Surgical Never Events Happen Nevertheless Surgeons call them "never events", because they ...

  5. base64编码方式

    一.编码的两大方式: 在python3.x中,字符串编码分为unicode和bytes两大类编码方式. 直接书写s='中国人',这种方式定义的编码方式为unicode,是通用的方式. 另一种是byte ...

  6. linux 进程学习笔记-信号semaphore

    信号灯(信号量)不是进程通信手段,其是用于控制和协调在进程间通信过程中的共享资源访问,就如同互斥锁(两者的区别可以参考这里) 可以将简单地将信号灯想象成一个计数器,初始时计数器值为n(有n个资源可供使 ...

  7. 用PCA降维 (Principal Component Analysis,主成分分析)

    参考资料:Mastering Machine Learning With scikit-learn 降维致力于解决三类问题.第一,降维可以缓解维度灾难问题.第二,降维可以在压缩数据的同时让信息损失最 ...

  8. BZOJ3196:二逼平衡树

    浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 浅谈\(Splay\):https://www.cnblogs.com/AKMer/p/ ...

  9. WPF ChangePropertyAction中TargetName和TargetObject的区别

    在wpf页面布局中经常用到ChangePropertyAction来更改属性,在这个里面有TargetName和TargetObject两个属性,都表示需要修改的控件名称,那么这两个有什么区别呢,通过 ...

  10. boost编译配置及简单使用

    boost编译配置及简单使用 1.下载 http://www.boost.org/ 2.编译: A.解压 boost_1_55_0.zip 到boost路径 B.运行 bootstrap.bat. 会 ...